You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "leaves12138 (via GitHub)" <gi...@apache.org> on 2024/04/16 10:02:42 UTC

[PR] [core] Enable file index for map type with map-keys. [paimon]

leaves12138 opened a new pull request, #3221:
URL: https://github.com/apache/paimon/pull/3221

   * API
   If you want to create a file index with map-keys, you need to specify.
   ```sql
   CREATE TABLE <PAIMON_TABLE> (<COLUMN> <COLUMN_TYPE> , ...) WITH
   (
   "file-index.bloom-filter.columns" = "map_data",
   "file-index.bloom-filter.map_data.items" = "200", --optional
   "file-index.bloom-filter.map_data.fpp" = "0.1",  --optional
   "file-index.bloom-filter.map_data.map-keys" = "key1,key2,key3,key4",  --needed      
   "file-index.in-manifest-threshold" = "500 B" --optional
   )
   ```
   
   * NOTE
   1. flink sql read `select * from <table> where map_data['key1'] = 'value1'` will not push down
   2. Every key in `map-keys` will generate a standalone bloom-filter, so if just need to predicate map_data['key1'] will not all map_data bloom-filter, just only map_data['key1'] bloom-filter.
   3. `map-keys` refer to clickhouse "INDEX map_key_index mapKeys(map_column) TYPE bloom_filter GRANULARITY 1"
   


-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #3221:
URL: https://github.com/apache/paimon/pull/3221#issuecomment-2065674059

   I prefer `"file-index.bloom-filter.columns" = "map_data[key1]"`.


-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575593268


##########
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexOptions.java:
##########
@@ -44,13 +50,40 @@ public FileIndexOptions(long fileIndexInManifestThreshold) {
     }
 
     public void computeIfAbsent(String column, String indexType) {

Review Comment:
   You should merge `CoreOptions.indexColumnsOptions` into this class.
   
   And remove `isExternallyPerceptible`.



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575590345


##########
paimon-core/src/main/java/org/apache/paimon/io/FileIndexWriter.java:
##########
@@ -51,7 +57,8 @@ public final class FileIndexWriter implements Closeable {
     // if the filter size greater than fileIndexInManifestThreshold, we put it in file
     private final long inManifestThreshold;
 
-    private final List<IndexMaintainer> indexMaintainers = new ArrayList<>();
+    private final List<FileIndexMaintainer> fileIndexMaintainers = new ArrayList<>();
+    private final Map<String, MapFileIndexMaintainer> mapFileIndexMaintainers = new HashMap<>();

Review Comment:
   You should unify fileIndexMaintainers to this Map.



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575590972


##########
paimon-common/src/main/java/org/apache/paimon/options/Options.java:
##########
@@ -94,6 +102,15 @@ public synchronized String get(String key) {
         return data.get(key);
     }
 
+    public synchronized <X extends Throwable> String getOrThrow(String key, Supplier<X> supplier)

Review Comment:
   supplier -> exSupplier



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 commented on PR #3221:
URL: https://github.com/apache/paimon/pull/3221#issuecomment-2068775683

   This pull request is ready for review. @JingsongLi 


-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #3221:
URL: https://github.com/apache/paimon/pull/3221


-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575597799


##########
paimon-core/src/main/java/org/apache/paimon/io/FileIndexWriter.java:
##########
@@ -191,4 +237,76 @@ public byte[] serializedBytes() {
             return fileIndexWriter.serializedBytes();
         }
     }
+
+    /** File index writer for map data type. */
+    private static class MapFileIndexMaintainer {
+
+        private final String columnName;
+        private final String indexType;
+        private final Options options;
+        private final DataType valueType;
+        private final Map<String, org.apache.paimon.fileindex.FileIndexWriter> indexWritersMap;
+        private final InternalArray.ElementGetter valueElementGetter;
+        private final int position;
+
+        public MapFileIndexMaintainer(
+                String columnName,
+                String indexType,
+                DataType keyType,
+                DataType valueType,
+                Options options,
+                int position) {
+            this.columnName = columnName;
+            this.indexType = indexType;
+            this.valueType = valueType;
+            this.options = options;
+            this.position = position;
+            this.indexWritersMap = new HashMap<>();
+            this.valueElementGetter = InternalArray.createElementGetter(valueType);
+
+            DataTypeRoot rootType = keyType.getTypeRoot();
+            if (rootType != DataTypeRoot.CHAR && rootType != DataTypeRoot.VARCHAR) {
+                throw new IllegalArgumentException(
+                        "Only support map data type with key field of CHAR、VARCHAR、STRING.");
+            }
+        }
+
+        public void write(InternalRow row) {
+            InternalMap internalMap = row.getMap(position);
+            InternalArray keyArray = internalMap.keyArray();
+            InternalArray valueArray = internalMap.valueArray();
+
+            for (int i = 0; i < keyArray.size(); i++) {
+                String key = keyArray.getString(i).toString();
+                org.apache.paimon.fileindex.FileIndexWriter writer =
+                        indexWritersMap.getOrDefault(key, null);
+                if (writer != null) {
+                    writer.write(valueElementGetter.getElementOrNull(valueArray, i));
+                }
+            }
+        }
+
+        public void add(String nestedKey, Options nestedOptions) {
+            indexWritersMap.put(
+                    nestedKey,
+                    FileIndexer.create(
+                                    indexType,
+                                    valueType,
+                                    new Options(options.toMap(), nestedOptions.toMap()))
+                            .createWriter());
+        }
+
+        public String getIndexType() {
+            return indexType;
+        }
+
+        public Map<String, byte[]> serializedBytes() {
+            Map<String, byte[]> result = new HashMap<>();
+            indexWritersMap.forEach(
+                    (k, v) ->
+                            result.put(
+                                    FileIndexCommon.toMapKey(columnName, k), v.serializedBytes()));

Review Comment:
   You need to consider no value in this file. We should have a special mechanism to compress this situation.



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575594130


##########
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexCommon.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.fileindex;
+
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.MapType;
+
+import java.util.Map;
+import java.util.Optional;
+
+/** Common function of file index put here. */
+public class FileIndexCommon {
+
+    public static String toMapKey(String mapColumnName, String keyName) {
+        return mapColumnName + "[" + keyName + "]";
+    }
+
+    public static DataType getFieldType(Map<String, DataField> fields, String columnsName) {
+        Optional<Integer> nestedIndex = FileIndexOptions.getNestedColumn(columnsName);

Review Comment:
   topLevelIndex



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575594341


##########
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexCommon.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.fileindex;
+
+import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.MapType;
+
+import java.util.Map;
+import java.util.Optional;
+
+/** Common function of file index put here. */
+public class FileIndexCommon {
+
+    public static String toMapKey(String mapColumnName, String keyName) {
+        return mapColumnName + "[" + keyName + "]";
+    }
+
+    public static DataType getFieldType(Map<String, DataField> fields, String columnsName) {
+        Optional<Integer> nestedIndex = FileIndexOptions.getNestedColumn(columnsName);

Review Comment:
   getNestedColumn -> topLevelIndexOfNested



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3221:
URL: https://github.com/apache/paimon/pull/3221#discussion_r1575594780


##########
paimon-common/src/main/java/org/apache/paimon/fileindex/FileIndexOptions.java:
##########
@@ -63,7 +96,82 @@ public long fileIndexInManifestThreshold() {
         return fileIndexInManifestThreshold;
     }
 
-    public Set<Map.Entry<String, Map<String, Options>>> entrySet() {
-        return indexTypeOptions.entrySet();
+    public Set<Map.Entry<Column, Map<String, Options>>> entrySet() {
+        return indexTypeOptions.entrySet().stream()
+                .filter(entry -> entry.getKey().isExternallyPerceptible())
+                .collect(Collectors.toSet());
+    }
+
+    public static Optional<Integer> getNestedColumn(String column) {
+        if (IS_NESTED.matcher(column).find()) {

Review Comment:
   Can we avoid using `regex.Pattern`?



-- 
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: issues-unsubscribe@paimon.apache.org

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


Re: [PR] [core] Enable file index for map type with map-keys. [paimon]

Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 commented on PR #3221:
URL: https://github.com/apache/paimon/pull/3221#issuecomment-2065903573

   > I prefer `"file-index.bloom-filter.columns" = "map_data[key1]"`.
   
   `file-index.bloom-filter.map_data##key1.items` convert to `file-index.bloom-filter.map_data[key1].items` ?


-- 
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: issues-unsubscribe@paimon.apache.org

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