在一个 table 中找到另一个 table 中不存在的 ID

Find IDs in one table not present in another table

给定 Cassandra 中的两个表:

xs (id bigint, x bigint)
0,10
1,11
2,12
3,13
4,14

ys (id bigint, y bigint)
0,100
2,144
4,196

在这个最小的示例中,我想从 xs 中获取所有行,其中 id 尚未包含在 ys 中,即

select
1,11
3,13

我怎样才能做到这一点?

基于我想在 ys 中创建新行的选定行,基本上同步(仅添加)ysxs

这是我创建 keyspaces/tables:

的代码
from cassandra.cluster import Cluster

cluster = Cluster()
session = cluster.connect()

session.execute('DROP KEYSPACE keyspace_x;')
session.execute('DROP KEYSPACE keyspace_y;')

session.execute('''
    CREATE KEYSPACE keyspace_x
    WITH replication = {
        'class' : 'SimpleStrategy',
        'replication_factor' : 1
    };''');

session.execute('''
    CREATE KEYSPACE keyspace_y
    WITH replication = {
        'class' : 'SimpleStrategy',
        'replication_factor' : 1
    };''');

session.execute('''CREATE TABLE keyspace_x.xs (
    id bigint,
    x bigint,
    PRIMARY KEY (id)
);''');

session.execute('''CREATE TABLE keyspace_y.ys (
    id bigint,
    y bigint,
    PRIMARY KEY (id)
);''');

session.execute('INSERT INTO keyspace_x.xs(id, x) VALUES (%s, %s)',(0, 10))
session.execute('INSERT INTO keyspace_x.xs(id, x) VALUES (%s, %s)',(1, 11))
session.execute('INSERT INTO keyspace_x.xs(id, x) VALUES (%s, %s)',(2, 12))
session.execute('INSERT INTO keyspace_x.xs(id, x) VALUES (%s, %s)',(3, 13))
session.execute('INSERT INTO keyspace_x.xs(id, x) VALUES (%s, %s)',(4, 14))

session.execute('INSERT INTO keyspace_y.ys(id, y) VALUES (%s, %s)',(0, 100))
session.execute('INSERT INTO keyspace_y.ys(id, y) VALUES (%s, %s)',(2, 144))
session.execute('INSERT INTO keyspace_y.ys(id, y) VALUES (%s, %s)',(4, 196))

SQL I would use something like that

SELECT xs.id, xs.x FROM xs
LEFT JOIN ys ON xs.id = ys.id
WHERE ys.id IS NULL;

但是 CQL 呢?

目前我只是从两个表中获取所有 ID 并在我的应用程序中设置差异,但我想这远非最佳。

没有多 table 功能。 How implement LEFT or RIGHT JOIN using spark-cassandra-connector You can add relational layers onto Cassandra. How to do a join queries with 2 or more tables in cassandra cql You can fruitlessly search the manual. http://cassandra.apache.org/doc/latest/cql/dml.html 回复 browsing/googling:其他 SQL 方法是 EXCEPT 又名 MINUSNOT IN。代数函数是 DIFFERENCE 又名 MINUS & ANTIJOIN).