You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2023/01/05 07:59:19 UTC

[GitHub] [ignite-3] ygerzhedovich commented on a diff in pull request #1476: IGNITE-18442 Sql. JOIN with DISTINCT FROM fails.

ygerzhedovich commented on code in PR #1476:
URL: https://github.com/apache/ignite-3/pull/1476#discussion_r1061446858


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java:
##########
@@ -376,31 +377,46 @@ public static List<RexNode> buildHashSearchRow(
             return null;
         }
 
-        List<RexNode> searchPreds = null;
+        List<SearchBounds> bounds = null;
+
+        List<RelDataType> types = RelOptUtil.getFieldTypeList(rowType);
+
+        Mappings.TargetMapping mapping = null;
+
+        if (requiredColumns != null) {
+            mapping = Commons.inverseTrimmingMapping(types.size(), requiredColumns);
+        }
+
+        for (Entry<List<RexCall>> fld : fieldsToPredicates.int2ObjectEntrySet()) {
+            List<RexCall> collFldPreds = fld.getValue();
 
-        for (List<RexCall> collFldPreds : fieldsToPredicates.values()) {
             if (nullOrEmpty(collFldPreds)) {
                 break;
             }
 
             for (RexCall pred : collFldPreds) {
-                if (pred.getOperator().kind != SqlKind.EQUALS) {
+                if (!pred.isA(List.of(EQUALS, IS_NOT_DISTINCT_FROM))) {

Review Comment:
   Will be better have private static EnumSet instead of creating collection each time?



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java:
##########
@@ -361,46 +364,58 @@ public static List<SearchBounds> buildHashIndexConditions(
     }
 
     /**
-     * Builds index conditions.
+     * Builds hash index search bounds.
      */
-    public static List<RexNode> buildHashSearchRow(
+    public static List<SearchBounds> buildHashSearchBounds(
             RelOptCluster cluster,
             RexNode condition,
-            RelDataType rowType
+            RelDataType rowType,
+            @Nullable ImmutableBitSet requiredColumns
     ) {
         condition = RexUtil.toCnf(builder(cluster), condition);
 
-        Int2ObjectMap<List<RexCall>> fieldsToPredicates = mapPredicatesToFields(condition, cluster);
+        Map<Integer, List<RexCall>> fieldsToPredicates = mapPredicatesToFields(condition, cluster);
 
         if (nullOrEmpty(fieldsToPredicates)) {
             return null;
         }
 
-        List<RexNode> searchPreds = null;
+        List<SearchBounds> bounds = null;
+
+        List<RelDataType> types = RelOptUtil.getFieldTypeList(rowType);
+
+        Mappings.TargetMapping mapping = null;
+
+        if (requiredColumns != null) {
+            mapping = Commons.inverseTrimmingMapping(types.size(), requiredColumns);
+        }
+
+        for (int fldIdx : fieldsToPredicates.keySet()) {
+            List<RexCall> collFldPreds = fieldsToPredicates.get(fldIdx);
 
-        for (List<RexCall> collFldPreds : fieldsToPredicates.values()) {
             if (nullOrEmpty(collFldPreds)) {
                 break;
             }
 
             for (RexCall pred : collFldPreds) {
-                if (pred.getOperator().kind != SqlKind.EQUALS) {
+                if (pred.getOperator().kind != SqlKind.EQUALS && pred.getOperator().kind != IS_NOT_DISTINCT_FROM) {

Review Comment:
   I mean create like it:
   `Set<SqlKind> SEARCH_OPERATOR =  EnumSet.of(SqlKind.EQUALS, SqlKind.IS_NOT_DISTINC_FROM)`
   and use `pred.isA(SEARCH_OPERATOR)`



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/RexUtils.java:
##########
@@ -361,46 +364,58 @@ public static List<SearchBounds> buildHashIndexConditions(
     }
 
     /**
-     * Builds index conditions.
+     * Builds hash index search bounds.
      */
-    public static List<RexNode> buildHashSearchRow(
+    public static List<SearchBounds> buildHashSearchBounds(
             RelOptCluster cluster,
             RexNode condition,
-            RelDataType rowType
+            RelDataType rowType,
+            @Nullable ImmutableBitSet requiredColumns
     ) {
         condition = RexUtil.toCnf(builder(cluster), condition);
 
-        Int2ObjectMap<List<RexCall>> fieldsToPredicates = mapPredicatesToFields(condition, cluster);
+        Map<Integer, List<RexCall>> fieldsToPredicates = mapPredicatesToFields(condition, cluster);
 
         if (nullOrEmpty(fieldsToPredicates)) {
             return null;
         }
 
-        List<RexNode> searchPreds = null;
+        List<SearchBounds> bounds = null;
+
+        List<RelDataType> types = RelOptUtil.getFieldTypeList(rowType);
+
+        Mappings.TargetMapping mapping = null;
+
+        if (requiredColumns != null) {
+            mapping = Commons.inverseTrimmingMapping(types.size(), requiredColumns);
+        }
+
+        for (int fldIdx : fieldsToPredicates.keySet()) {

Review Comment:
   it comment relates to both cases. But will be more efficient fix collections first and use int2ObjectEntrySet instead of iterating by keys and get value for each key



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org