【问题标题】:Is it possible to delete a single value in the shared cache of an IgniteRDD?是否可以删除 IgniteRDD 的共享缓存中的单个值?
【发布时间】:2020-05-09 01:28:45
【问题描述】:

是否可以从 Ignite 共享缓存 (IgniteRDD) 中删除特定项目?

例如,在下面的代码中,如何删除唯一的项目 (21, 21)?

val cacheRdd = igniteContext.fromCache("partitioned")

cacheRdd.savePairs(sparkContext.parallelize(1 to 10000, 10).map(i => (i, i)))

IgniteRDD 提供了一个名为clear() 的方法,用于从缓存中删除所有内容。有没有类似删除特定项目的东西?

【问题讨论】:

    标签: apache-spark rdd ignite


    【解决方案1】:

    我知道几种方法:

    1)使用SQL删除命令

    val cacheRdd = igniteContext.fromCache("Person")
    
    val result = cacheRdd.sql(
      "DELETE FROM PERSON WHERE ID=1")
    

    2)使用JCache API:

    // Creates Ignite context with specific configuration and runs Ignite in the embedded mode.
    JavaIgniteContext<Integer, Integer> igniteContext = new JavaIgniteContext<Integer, Integer>(
        sparkContext,"examples/config/spark/example-shared-rdd.xml", false);
    
    IgniteCache<Long, Person> personIgniteCache = igniteContext.ignite().getOrCreateCache("Person");
    
    personIgniteCache.remove(1L);
    

    同样来自 scala:

    val igniteContext = new IgniteContext(sparkContext, CONFIG, false)
    
    igniteContext.ignite().getOrCreateCache("Person");
    

    您也可以在您的驱动程序应用程序中启动 Ignite 节点。

    BR, 安德烈

    【讨论】:

    • 谢谢!我有一个与第二种方法有关的问题。如果我使用 JCache,我对缓存执行的操作的行为是否与使用 RDD 相同?也就是说,如果我做一个cache.foreach(),它会分布式运行吗?
    • 并非如此。 IgniteRDD 是存储在 Spark 中的分布式数据,可以使用内部数据流传输器将其存储到 Ignite 集群。 IgniteCache 实例是 Ignite 缓存的代理接口,可用于对其进行操作。 IgniteRdd 在里面使用了 IgniteContext。 IgniteContext 包含了该 RDD 用于在 Ignite 集群中进行分布式操作的 Ignite 客户端实例。所以这两个特性(IgniteRDD 和 IgniteCache)都会在 Ignite Cache 下产生分布式操作。但他们会使用不同的机制来做到这一点。
    猜你喜欢
    • 2015-07-13
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    相关资源
    最近更新 更多