Skip to content

Commit

Permalink
IGNITE-14823 Query abbrevation (#11232)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Feb 6, 2024
1 parent d5cf808 commit 968e6ec
Show file tree
Hide file tree
Showing 51 changed files with 316 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,16 @@ public void union() throws Exception {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"SELECT * FROM employer1 " +
"UNION " +
"SELECT * FROM employer2 " +
"UNION " +
"SELECT * FROM employer3 ");

assertEquals(1, query.size());
assertEquals(1, qry.size());

List<List<?>> rows = query.get(0).getAll();
List<List<?>> rows = qry.get(0).getAll();
assertEquals(3, rows.size());
}

Expand Down Expand Up @@ -695,12 +695,12 @@ public void aggregate() throws Exception {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"SELECT * FROM employer WHERE employer.salary = (SELECT AVG(employer.salary) FROM employer)");

assertEquals(1, query.size());
assertEquals(1, qry.size());

List<List<?>> rows = query.get(0).getAll();
List<List<?>> rows = qry.get(0).getAll();
assertEquals(1, rows.size());
assertEquals(Arrays.asList("Roman", 15d), F.first(rows));
}
Expand Down Expand Up @@ -768,12 +768,12 @@ public void query() throws Exception {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"select * from DEVELOPER d, PROJECT p where d.projectId = p._key and d._key = ?", 0);

assertEquals(1, query.size());
assertEquals(1, qry.size());

assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(query.get(0).getAll()));
assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(qry.get(0).getAll()));
}

/** */
Expand Down Expand Up @@ -801,12 +801,12 @@ public void query2() {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"select * from DEVELOPER d, PROJECT p where d.projectId = p._key and d._key = ?", 0);

assertEquals(1, query.size());
assertEquals(1, qry.size());

assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(query.get(0).getAll()));
assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(qry.get(0).getAll()));
}

/** */
Expand Down Expand Up @@ -838,17 +838,17 @@ public void queryMultiStatement() throws Exception {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"" +
"select * from DEVELOPER d, PROJECT p where d.projectId = p._key and d._key = ?;" +
"select * from DEVELOPER d, PROJECT p where d.projectId = p._key and d._key = 10;" +
"select * from DEVELOPER d, PROJECT p where d.projectId = p._key and d._key = ?", 0, 1);

assertEquals(3, query.size());
assertEquals(3, qry.size());

assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(query.get(0).getAll()));
assertEquals(0, query.get(1).getAll().size());
assertEqualsCollections(Arrays.asList("Roman", 0, "Ignite"), F.first(query.get(2).getAll()));
assertEqualsCollections(Arrays.asList("Igor", 1, "Calcite"), F.first(qry.get(0).getAll()));
assertEquals(0, qry.get(1).getAll().size());
assertEqualsCollections(Arrays.asList("Roman", 0, "Ignite"), F.first(qry.get(2).getAll()));
}

/**
Expand Down Expand Up @@ -1192,29 +1192,29 @@ public void testThroughput() {

// warmup
for (int i = 0; i < numIterations; i++) {
List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC", "select * from DEVELOPER");
query.get(0).getAll();
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC", "select * from DEVELOPER");
qry.get(0).getAll();
}

long start = System.currentTimeMillis();
for (int i = 0; i < numIterations; i++) {
List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC", "select * from DEVELOPER");
query.get(0).getAll();
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC", "select * from DEVELOPER");
qry.get(0).getAll();
}
System.out.println("Calcite duration = " + (System.currentTimeMillis() - start));

// warmup
for (int i = 0; i < numIterations; i++) {
List<FieldsQueryCursor<List<?>>> query = client.context().query().querySqlFields(
List<FieldsQueryCursor<List<?>>> qry = client.context().query().querySqlFields(
new SqlFieldsQuery("select * from DEVELOPER").setSchema("PUBLIC"), false, false);
query.get(0).getAll();
qry.get(0).getAll();
}

start = System.currentTimeMillis();
for (int i = 0; i < numIterations; i++) {
List<FieldsQueryCursor<List<?>>> query = client.context().query().querySqlFields(
List<FieldsQueryCursor<List<?>>> qry = client.context().query().querySqlFields(
new SqlFieldsQuery("select * from DEVELOPER").setSchema("PUBLIC"), false, false);
query.get(0).getAll();
qry.get(0).getAll();
}
System.out.println("H2 duration = " + (System.currentTimeMillis() - start));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ public static Collection<?> parameters() {
public void testCancelUnknownSqlQuery() {
IgniteEx srv = grid(0);
UUID nodeId = cancelOnClient ? client.localNode().id() : srv.localNode().id();
Long queryId = ThreadLocalRandom.current().nextLong(10, 10000);
Long qryId = ThreadLocalRandom.current().nextLong(10, 10000);
GridTestUtils.assertThrows(log, () -> {
sql(cancelOnClient ? client : srv, "KILL QUERY" + (isAsync ? " ASYNC '" : " '") + nodeId + "_"
+ queryId + "'");
+ qryId + "'");
},
IgniteException.class,
String.format("Failed to cancel query [nodeId=%s, qryId=%d, err=Query with provided ID doesn't exist " +
"[nodeId=%s, qryId=%d]]", nodeId, queryId, nodeId, queryId)
"[nodeId=%s, qryId=%d]]", nodeId, qryId, nodeId, qryId)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,29 +401,29 @@ private void testSelect(int sz, boolean withIn, String column) {
assertTrue(sz >= 1);
int[] values = ThreadLocalRandom.current().ints(0, ENTRIES_COUNT).distinct().limit(sz).toArray();

StringBuilder query;
StringBuilder qry;

if (!withIn || sz == 1)
query = new StringBuilder("select * from T1 where ");
qry = new StringBuilder("select * from T1 where ");
else
query = new StringBuilder("select * from T1 where T1.").append(column).append(" in (");
qry = new StringBuilder("select * from T1 where T1.").append(column).append(" in (");

for (int i = 0; i < sz; ++i) {
if (!withIn || sz == 1)
query.append("T1.").append(column).append("= ?");
qry.append("T1.").append(column).append("= ?");
else
query.append('?');
qry.append('?');

if (sz == 1)
break;

if (i == sz - 1)
query.append(!withIn ? "" : ")");
qry.append(!withIn ? "" : ")");
else
query.append(!withIn ? " OR " : ", ");
qry.append(!withIn ? " OR " : ", ");
}

execute(query.toString(),
execute(qry.toString(),
res -> {
assertPartitions(IntStream.of(values).map(i -> partition("T1_CACHE", i)).toArray());
assertNodes(IntStream.of(values).mapToObj(i -> node("T1_CACHE", i)).toArray(ClusterNode[]::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void testPerformanceStatistics() throws Exception {
Set<UUID> dataNodesIds = new HashSet<>(F.asList(grid(0).localNode().id(), grid(1).localNode().id()));
Set<UUID> readsNodes = new HashSet<>(dataNodesIds);
Set<Long> readsQueries = new HashSet<>();
Map<Long, Long> rowsFetchedPerQuery = new HashMap<>();
Map<Long, Long> rowsFetchedPerQry = new HashMap<>();
AtomicLong firstQryId = new AtomicLong(-1);
AtomicLong lastQryId = new AtomicLong();

Expand Down Expand Up @@ -420,16 +420,16 @@ public void testPerformanceStatistics() throws Exception {
}
else if ("Fetched".equals(action)) {
assertEquals(grid(0).localNode().id(), nodeId);
assertNull(rowsFetchedPerQuery.put(id, rows));
assertNull(rowsFetchedPerQry.put(id, rows));
}
}
});

assertEquals(4, qryCnt.get());
assertTrue("Query reads expected on nodes: " + readsNodes, readsNodes.isEmpty());
assertEquals(Collections.singleton(lastQryId.get()), readsQueries);
assertEquals((Long)1000L, rowsFetchedPerQuery.get(firstQryId.get()));
assertEquals((Long)4L, rowsFetchedPerQuery.get(lastQryId.get()));
assertEquals((Long)1000L, rowsFetchedPerQry.get(firstQryId.get()));
assertEquals((Long)4L, rowsFetchedPerQry.get(lastQryId.get()));
assertEquals(5L, rowsScanned.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,13 @@ public void alterTableLogging() {
*/
@Test
public void testMulitlineWithCreateTable() {
String multiLineQuery = "CREATE TABLE test (val0 int primary key, val1 varchar);" +
String multiLineQry = "CREATE TABLE test (val0 int primary key, val1 varchar);" +
"INSERT INTO test(val0, val1) VALUES (0, 'test0');" +
"ALTER TABLE test ADD COLUMN val2 int;" +
"INSERT INTO test(val0, val1, val2) VALUES(1, 'test1', 10);" +
"ALTER TABLE test DROP COLUMN val2;";

sql(multiLineQuery);
sql(multiLineQry);

List<List<?>> res = sql("SELECT * FROM test order by val0");
assertEquals(2, res.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public void testInsertPrimitiveKey() {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC",
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC",
"INSERT INTO DEVELOPER(_key, name, projectId) VALUES (?, ?, ?)", 0, "Igor", 1);

assertEquals(1, query.size());
assertEquals(1, qry.size());

List<List<?>> rows = query.get(0).getAll();
List<List<?>> rows = qry.get(0).getAll();

assertEquals(1, rows.size());

Expand All @@ -167,11 +167,11 @@ public void testInsertPrimitiveKey() {

assertEqualsCollections(F.asList(1L), row);

query = engine.query(null, "PUBLIC", "select _key, * from DEVELOPER");
qry = engine.query(null, "PUBLIC", "select _key, * from DEVELOPER");

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNotNull(row);

Expand All @@ -192,61 +192,61 @@ public void testInsertUpdateDeleteNonPrimitiveKey() throws Exception {

QueryEngine engine = Commons.lookupComponent(grid(1).context(), QueryEngine.class);

List<FieldsQueryCursor<List<?>>> query = engine.query(null, "PUBLIC", "INSERT INTO DEVELOPER VALUES (?, ?, ?, ?)", 0, 0, "Igor", 1);
List<FieldsQueryCursor<List<?>>> qry = engine.query(null, "PUBLIC", "INSERT INTO DEVELOPER VALUES (?, ?, ?, ?)", 0, 0, "Igor", 1);

assertEquals(1, query.size());
assertEquals(1, qry.size());

List<?> row = F.first(query.get(0).getAll());
List<?> row = F.first(qry.get(0).getAll());

assertNotNull(row);

assertEqualsCollections(F.asList(1L), row);

query = engine.query(null, "PUBLIC", "select * from DEVELOPER");
qry = engine.query(null, "PUBLIC", "select * from DEVELOPER");

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNotNull(row);

assertEqualsCollections(F.asList(0, 0, "Igor", 1), row);

query = engine.query(null, "PUBLIC", "UPDATE DEVELOPER d SET name = name || 'Roman' WHERE id = ?", 0);
qry = engine.query(null, "PUBLIC", "UPDATE DEVELOPER d SET name = name || 'Roman' WHERE id = ?", 0);

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNotNull(row);

assertEqualsCollections(F.asList(1L), row);

query = engine.query(null, "PUBLIC", "select * from DEVELOPER");
qry = engine.query(null, "PUBLIC", "select * from DEVELOPER");

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNotNull(row);

assertEqualsCollections(F.asList(0, 0, "IgorRoman", 1), row);

query = engine.query(null, "PUBLIC", "DELETE FROM DEVELOPER WHERE id = ?", 0);
qry = engine.query(null, "PUBLIC", "DELETE FROM DEVELOPER WHERE id = ?", 0);

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNotNull(row);

assertEqualsCollections(F.asList(1L), row);

query = engine.query(null, "PUBLIC", "select * from DEVELOPER");
qry = engine.query(null, "PUBLIC", "select * from DEVELOPER");

assertEquals(1, query.size());
assertEquals(1, qry.size());

row = F.first(query.get(0).getAll());
row = F.first(qry.get(0).getAll());

assertNull(row);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ public void testBatchPrepared() throws Exception {
*/
@Test
public void testMultilineQuery() throws Exception {
String multiLineQuery = "CREATE TABLE test (val0 int primary key, val1 varchar);" +
String multiLineQry = "CREATE TABLE test (val0 int primary key, val1 varchar);" +
"INSERT INTO test(val0, val1) VALUES (0, 'test0');" +
"ALTER TABLE test ADD COLUMN val2 int;" +
"INSERT INTO test(val0, val1, val2) VALUES(1, 'test1', 10);" +
"ALTER TABLE test DROP COLUMN val2;";
stmt.execute(multiLineQuery);
stmt.execute(multiLineQry);

try (ResultSet rs = stmt.executeQuery("select * from test order by val0")) {
int i;
Expand Down
Loading

0 comments on commit 968e6ec

Please sign in to comment.