首页 > 解决方案 > 是否可以删除 IgniteRDD 的共享缓存中的单个值?

问题描述

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

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

val cacheRdd = igniteContext.fromCache("partitioned")

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

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

标签: apache-sparkrddignite

解决方案


我知道几种方法:

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,安德烈


推荐阅读