如何使用 java 中的列表从 aerospike 获取记录?
How to Get record from aerospike using list in java?
My data at test.setName looks like this
| id | cities | lob |
|-------|---------------------|------------|
| id123 | ["Cthdcn","Ctdel"] | ["Lob132"] |
| id345 | ["Ctijs","Ctdelhi"] | ["LOB231"] |
| id765 | ["Cthui"] | ["Lob875"] |
“cities”已经作为 LIST INDEX 存在,并且想要获得一个
通过指定城市数组 like(["Ctijs","Ctdelhi"]) 的特定记录
通过 java 客户端。
我想通过使用指定城市数组来检索(获取)记录
java。我正在使用以下方法
public Record testGet(String namespace, String set, String city, List<String> binNames) {
Statement statement = new Statement();
statement.setNamespace(namespace);
statement.setSetName(set);
Filter filter = Filter.contains("cities", IndexCollectionType.LIST, city);
statement.setFilter(filter);
RecordSet records = this.client.query((QueryPolicy)null, statement);
return records.getRecord();
}
我正在获取空值。我如何检索该特定记录? (AQL 版本 3.23.0)
这是一个文本文件 list.aql 中的 AQL 小脚本,用于复制您的测试:
list.aql:
TRUNCATE test
DROP INDEX test.setName idx_city
SELECT * FROM test
CREATE LIST INDEX idx_city ON test.setName (cities) STRING
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key1', 'id123', LIST('["Cthdcn", "Ctdel"]'), LIST('["Lob132
"]'))
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key2', 'id345', LIST('["Ctijs", "Ctdelhi"]'), LIST('["LOB23
1"]'))
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key3', 'id765', LIST('["Cthui"]'), LIST('["Lob875"]'))
select * from test.setName
select * from test.setName in LIST where cities = 'Cthdcn'
aql 中的输出:
aql> run 'list.aql'
TRUNCATE test
OK
DROP INDEX test.setName idx_city
Error: (201) Index does not exist on the system.
SELECT * FROM test
0 rows in set (0.156 secs)
OK
CREATE LIST INDEX idx_city ON test.setName (cities) STRING
OK, 1 index added.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key1', 'id123', LIST('["Cthdcn", "Ctdel"]'), LIST('["Lob132"]'))
OK, 1 record affected.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key2', 'id345', LIST('["Ctijs", "Ctdelhi"]'), LIST('["LOB231"]'))
OK, 1 record affected.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key3', 'id765', LIST('["Cthui"]'), LIST('["Lob875"]'))
OK, 1 record affected.
select * from test.setName
+---------+------------------------------+--------------------+
| id | cities | lob |
+---------+------------------------------+--------------------+
| "id123" | LIST('["Cthdcn", "Ctdel"]') | LIST('["Lob132"]') |
| "id765" | LIST('["Cthui"]') | LIST('["Lob875"]') |
| "id345" | LIST('["Ctijs", "Ctdelhi"]') | LIST('["LOB231"]') |
+---------+------------------------------+--------------------+
3 rows in set (0.124 secs)
OK
select * from test.setName in LIST where cities = 'Cthdcn'
+---------+-----------------------------+--------------------+
| id | cities | lob |
+---------+-----------------------------+--------------------+
| "id123" | LIST('["Cthdcn", "Ctdel"]') | LIST('["Lob132"]') |
+---------+-----------------------------+--------------------+
1 row in set (0.001 secs)
OK
aql>
在 Java 中,您将必须遍历记录集以获取满足查询的每条记录。
RecordSet records = client.query( .....)
while (records.next()){
Record r = records.getRecord();
....
}
records.close()
我刚刚测试了以下代码:
public void read () {
Record record = null;
Statement stmt = new Statement();
stmt.setSetName("setName");
stmt.setNamespace("test");
stmt.setIndexName("idx_city");
stmt.setFilter(Filter.contains("cities", IndexCollectionType.LIST, "Cthui"));
RecordSet recordSet = this.client.query(queryPolicy, stmt);
while (recordSet.next()) {
record = recordSet.getRecord();
System.out.println(record.toString());
}
}
它对我有用。
$ java -jar ./target/dm-predicateFilter-1.0-full.jar
(gen:1),(exp:348432597),(bins:(id:id765),(cities:[Cthui]),(lob:[Lob875]))
My data at test.setName looks like this
| id | cities | lob |
|-------|---------------------|------------|
| id123 | ["Cthdcn","Ctdel"] | ["Lob132"] |
| id345 | ["Ctijs","Ctdelhi"] | ["LOB231"] |
| id765 | ["Cthui"] | ["Lob875"] |
“cities”已经作为 LIST INDEX 存在,并且想要获得一个 通过指定城市数组 like(["Ctijs","Ctdelhi"]) 的特定记录 通过 java 客户端。
我想通过使用指定城市数组来检索(获取)记录 java。我正在使用以下方法
public Record testGet(String namespace, String set, String city, List<String> binNames) {
Statement statement = new Statement();
statement.setNamespace(namespace);
statement.setSetName(set);
Filter filter = Filter.contains("cities", IndexCollectionType.LIST, city);
statement.setFilter(filter);
RecordSet records = this.client.query((QueryPolicy)null, statement);
return records.getRecord();
}
我正在获取空值。我如何检索该特定记录? (AQL 版本 3.23.0)
这是一个文本文件 list.aql 中的 AQL 小脚本,用于复制您的测试:
list.aql:
TRUNCATE test
DROP INDEX test.setName idx_city
SELECT * FROM test
CREATE LIST INDEX idx_city ON test.setName (cities) STRING
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key1', 'id123', LIST('["Cthdcn", "Ctdel"]'), LIST('["Lob132
"]'))
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key2', 'id345', LIST('["Ctijs", "Ctdelhi"]'), LIST('["LOB23
1"]'))
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key3', 'id765', LIST('["Cthui"]'), LIST('["Lob875"]'))
select * from test.setName
select * from test.setName in LIST where cities = 'Cthdcn'
aql 中的输出:
aql> run 'list.aql'
TRUNCATE test
OK
DROP INDEX test.setName idx_city
Error: (201) Index does not exist on the system.
SELECT * FROM test
0 rows in set (0.156 secs)
OK
CREATE LIST INDEX idx_city ON test.setName (cities) STRING
OK, 1 index added.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key1', 'id123', LIST('["Cthdcn", "Ctdel"]'), LIST('["Lob132"]'))
OK, 1 record affected.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key2', 'id345', LIST('["Ctijs", "Ctdelhi"]'), LIST('["LOB231"]'))
OK, 1 record affected.
INSERT INTO test.setName (PK, id, cities, lob) VALUES ('key3', 'id765', LIST('["Cthui"]'), LIST('["Lob875"]'))
OK, 1 record affected.
select * from test.setName
+---------+------------------------------+--------------------+
| id | cities | lob |
+---------+------------------------------+--------------------+
| "id123" | LIST('["Cthdcn", "Ctdel"]') | LIST('["Lob132"]') |
| "id765" | LIST('["Cthui"]') | LIST('["Lob875"]') |
| "id345" | LIST('["Ctijs", "Ctdelhi"]') | LIST('["LOB231"]') |
+---------+------------------------------+--------------------+
3 rows in set (0.124 secs)
OK
select * from test.setName in LIST where cities = 'Cthdcn'
+---------+-----------------------------+--------------------+
| id | cities | lob |
+---------+-----------------------------+--------------------+
| "id123" | LIST('["Cthdcn", "Ctdel"]') | LIST('["Lob132"]') |
+---------+-----------------------------+--------------------+
1 row in set (0.001 secs)
OK
aql>
在 Java 中,您将必须遍历记录集以获取满足查询的每条记录。
RecordSet records = client.query( .....)
while (records.next()){
Record r = records.getRecord();
....
}
records.close()
我刚刚测试了以下代码:
public void read () {
Record record = null;
Statement stmt = new Statement();
stmt.setSetName("setName");
stmt.setNamespace("test");
stmt.setIndexName("idx_city");
stmt.setFilter(Filter.contains("cities", IndexCollectionType.LIST, "Cthui"));
RecordSet recordSet = this.client.query(queryPolicy, stmt);
while (recordSet.next()) {
record = recordSet.getRecord();
System.out.println(record.toString());
}
}
它对我有用。
$ java -jar ./target/dm-predicateFilter-1.0-full.jar
(gen:1),(exp:348432597),(bins:(id:id765),(cities:[Cthui]),(lob:[Lob875]))