zstan commented on code in PR #13225:
URL: https://github.com/apache/ignite/pull/13225#discussion_r3490153604
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SelectByKeyFieldTest.java:
##########
@@ -304,32 +193,158 @@ private void checkCompositePk(
}
/** */
- private void checkCompositePkWithDifferentCmpOperations(boolean
useBinaryObject) {
+ @Test
+ public void testCompositePkSearchByPartOfKeyTableScan() {
+ compositePkEqualitySearchByPartOfKey(true);
+ }
+
+ /** */
+ @Test
+ public void testCompositePkSearchByPartOfKeyIdxScan() {
+ compositePkEqualitySearchByPartOfKey(false);
+ }
+
+ /**
+ * Tests composite primary key equality search using only part of the key
(single column).
+ * Verifies that queries with equality comparison on either the {@code id}
or {@code name} column
+ * return correct results using either table scan or index scan depending
on the {@code tableScan} flag.
+ *
+ * @param tableScan {@code true} to test with table scan, {@code false} to
test with index scan.
+ */
+ public void compositePkEqualitySearchByPartOfKey(boolean tableScan) {
sql("create table PUBLIC.PERSON(id int, name varchar, surname varchar,
age int, primary key(id, name))");
- for (int i = 0; i < 10; i++) {
- sql(
- "insert into PUBLIC.PERSON(id, name, surname, age) values (?,
?, ?, ?)",
- i, "foo" + i, "bar" + i, 18 + i
- );
- }
+ fillTable();
+
+ List<List<?>> sqlRs = sql("select _key, id, name from PUBLIC.PERSON
order by id");
+ BinaryObject _key = (BinaryObject)sqlRs.get(6).get(0);
+ int id = (Integer)sqlRs.get(6).get(1);
+ String name = (String)sqlRs.get(6).get(2);
+
+ // Select by uniq id.
+ assertQuery("select /*+ DISABLE_RULE('" + (tableScan ?
"LogicalIndexScanConverterRule" : "LogicalTableScanConverterRule") +
+ "') */ id, name, age, _key from PUBLIC.PERSON where id = ?")
+ .withParams(id)
+ .matches(tableScan ?
+ QueryChecker.containsTableScan("PUBLIC", "PERSON") :
+ QueryChecker.containsIndexScan("PUBLIC", "PERSON",
PRIMARY_KEY_INDEX)
+ )
+ .columnNames("ID", "NAME", "AGE", KEY_FIELD_NAME)
+ .returns(id, name, 24, _key)
+ .check();
+
+ // Select by uniq name.
+ assertQuery("select /*+ DISABLE_RULE('" + (tableScan ?
"LogicalIndexScanConverterRule" : "LogicalTableScanConverterRule") +
+ "') */ id, name, age, _key from PUBLIC.PERSON where name = ?")
+ .withParams(name)
+ .matches(tableScan ?
+ QueryChecker.containsTableScan("PUBLIC", "PERSON") :
+ QueryChecker.containsIndexScan("PUBLIC", "PERSON",
PRIMARY_KEY_INDEX)
+ )
+ .columnNames("ID", "NAME", "AGE", KEY_FIELD_NAME)
+ .returns(id, name, 24, _key)
+ .check();
+ }
+
+ /** */
+ @Test
+ public void testCompositePkWithOrderByKeyTableScan() {
+ compositePkWithOrderByKey(true);
+ }
+
+ /** */
+ @Test
+ public void testCompositePkWithOrderByKeyIdxScan() {
+ compositePkWithOrderByKey(false);
+ }
+
+ /**
+ * Tests composite primary key ordering by {@code _key}.
+ * Verifies that ordering by the composite primary key produces correct
results
+ * when comparing binary objects using {@link #binaryObjectCmpForDml}.
+ */
+ public void compositePkWithOrderByKey(boolean tableScan) {
+ sql("create table PUBLIC.PERSON(id int, name varchar, surname varchar,
age int, primary key(id, name))");
+
+ fillTable();
+
+ List<List<?>> sqlRs = sql("select id, name, age, _key from
PUBLIC.PERSON");
+ sqlRs.sort((o1, o2) -> binaryObjectCmpForDml(o1.get(3), o2.get(3)));
+
+ QueryChecker qryChecker = assertQuery("select /*+ DISABLE_RULE('" +
+ (tableScan ? "LogicalIndexScanConverterRule" :
"LogicalTableScanConverterRule") +
+ "') */ id, name, age, _key from PUBLIC.PERSON order by _key")
+ .matches(tableScan ?
+ QueryChecker.containsTableScan("PUBLIC", "PERSON") :
+ QueryChecker.containsIndexScan("PUBLIC", "PERSON",
PRIMARY_KEY_INDEX)
+ )
+ .columnNames("ID", "NAME", "AGE", KEY_FIELD_NAME);
+
+ sqlRs.forEach(objects ->
qryChecker.returns(objects.toArray(Object[]::new)));
+
+ qryChecker.check();
+ }
+
+ /** */
+ @Test
+ public void testBinaryCompositePkComparisonsWithTableScan() {
+ checkCompositePkWithDifferentCmpOperations(true, true);
+ }
+
+ /** */
+ @Test
+ public void testBinaryCompositePkComparisonsWithIdxScan() {
+ checkCompositePkWithDifferentCmpOperations(true, false);
+ }
+
+ /** */
+ @Test
+ public void testJavaObjCompositePkComparisonsWithTableScan() {
+ checkCompositePkWithDifferentCmpOperations(false, true);
+ }
+
+ /** */
+ @Test
+ public void testJavaObjCompositePkComparisonsWithIdxScan() {
+ checkCompositePkWithDifferentCmpOperations(false, false);
+ }
+
+ /**
+ * Checks composite primary key comparisons with different comparison
operations.
+ * Creates a table with composite key (id, name) using {@link
PersonCompositeKey}, inserts test data,
+ * and verifies that all comparison operations (EQ, NE, LT, LE, GT, GE)
work correctly with both table scan
+ * and index scan query strategies.
+ *
+ * @param useBinaryObject {@code true} to use binary object representation
for key comparison,
+ * {@code false} to use deserialized object.
+ * @param tableScan {@code true} to test with table scan, {@code false} to
test with index scan.
+ */
+ private void checkCompositePkWithDifferentCmpOperations(boolean
useBinaryObject, boolean tableScan) {
+ sql(String.format(
+ "create table PUBLIC.PERSON(id int, name varchar, surname varchar,
age int, primary key(id, name)) with \"key_type=%s\"",
+ PersonCompositeKey.class.getName()
+ ));
+
+ fillTable();
List<List<?>> sqlRs = sql("select id, name, age, _key from
PUBLIC.PERSON order by id");
- BinaryObjectImpl _key8 = (BinaryObjectImpl)sqlRs.get(8).get(3);
- for (CmpOp cmpOp : CmpOp.values()) {
- if (cmpOp == CmpOp.EQ)
- continue;
+ Object key8 = sqlRs.get(8).get(3);
+ for (CmpOp cmpOp : CmpOp.values()) {
List<List<?>> expRows = sqlRs.stream()
- .filter(objects ->
cmpOp.expRowByKeyPred.test((BinaryObjectImpl)objects.get(3), _key8))
- .collect(toList());
+ .filter(objects ->
cmpOp.expRowByKeyPred.test((BinaryObjectImpl)objects.get(3), key8))
+ .toList();
QueryChecker qryChecker = assertQuery(String.format(
- "select id, name, age, _key from PUBLIC.PERSON where _key %s
?", cmpOp.sql
+ "select /*+ DISABLE_RULE('" + (tableScan ?
"LogicalIndexScanConverterRule" : "LogicalTableScanConverterRule") +
Review Comment:
because i want to run this and all other tests for index and table scan
operations
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]