[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=736591&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-736591 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 04/Mar/22 11:27 Start Date: 04/Mar/22 11:27 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r819490947 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +331,42 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} + +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); Review comment: As discussed offline this won't be addressed with this patch. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 736591) Time Spent: 6h 20m (was: 6h 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 6h 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=736593&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-736593 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 04/Mar/22 11:27 Start Date: 04/Mar/22 11:27 Worklog Time Spent: 10m Work Description: szlta merged pull request #3060: URL: https://github.com/apache/hive/pull/3060 -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 736593) Time Spent: 6.5h (was: 6h 20m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 6.5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735850&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735850 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 03/Mar/22 10:45 Start Date: 03/Mar/22 10:45 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r818531645 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +331,42 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} + +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); Review comment: You might want beat me with a stick for mentioning this only now, but `getPartitionTransformSpec(hmsTable)` starts with: ``` TableDesc tableDesc = Utilities.getTableDesc(hmsTable); Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); ``` We have the Iceberg table at hand. Would it be better to have a `private partitionTransformSpec(Table iceTable)` which could be called here, and from `getPartitionTransformSpec`? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 735850) Time Spent: 6h 10m (was: 6h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 6h 10m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735820&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735820 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 03/Mar/22 09:24 Start Date: 03/Mar/22 09:24 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r818463694 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,198 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private int numBuckets = -1; + private transient PrimitiveObjectInspector argumentOI; + private transient ObjectInspectorConverters.Converter converter; + + @FunctionalInterface + private interface UDFEvalFunction { +void apply(T argument) throws HiveException; + } + + private transient UDFEvalFunction evaluator; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 arguments (value, bucketCount), but got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHAR: + case VARCHAR: + case STRING: +converter = new PrimitiveObjectInspectorConverter.StringConverter(argumentOI); +evaluator = arg -> { + String val = (String) converter.convert(arg.get()); + applyBucketTransform(val, Types.StringType.get()); +}; +break; + + case BINARY: +converter = new PrimitiveObjectInspectorConverter.BinaryConverter(argumentOI, +
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735822&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735822 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 03/Mar/22 09:26 Start Date: 03/Mar/22 09:26 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r818465847 ## File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java ## @@ -77,7 +77,7 @@ ); private static final PartitionSpec PARTITIONED_SPEC = - PartitionSpec.builderFor(CUSTOMER_SCHEMA).bucket("customer_id", 3).build(); + PartitionSpec.builderFor(CUSTOMER_SCHEMA).identity("customer_id").build(); Review comment: Most of the write path is mocked out, Hive queries are not committed to test writes in this test class. That means no optimizers can run either, and thus the result set before a write would not be sorted by bucket function. With the absence of lenient ClusteredWriter this would make the test always fail for partitioned writes. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 735822) Time Spent: 6h (was: 5h 50m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 6h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735789&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735789 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 03/Mar/22 06:30 Start Date: 03/Mar/22 06:30 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r818351392 ## File path: iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergOutputCommitter.java ## @@ -77,7 +77,7 @@ ); private static final PartitionSpec PARTITIONED_SPEC = - PartitionSpec.builderFor(CUSTOMER_SCHEMA).bucket("customer_id", 3).build(); + PartitionSpec.builderFor(CUSTOMER_SCHEMA).identity("customer_id").build(); Review comment: I remember that you have already told me why is this change needed. Could you please refresh my memory? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 735789) Time Spent: 5h 40m (was: 5.5h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 5h 40m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735786&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735786 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 03/Mar/22 06:25 Start Date: 03/Mar/22 06:25 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r818349170 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,198 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorConverters; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private int numBuckets = -1; + private transient PrimitiveObjectInspector argumentOI; + private transient ObjectInspectorConverters.Converter converter; + + @FunctionalInterface + private interface UDFEvalFunction { +void apply(T argument) throws HiveException; + } + + private transient UDFEvalFunction evaluator; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 arguments (value, bucketCount), but got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHAR: + case VARCHAR: + case STRING: +converter = new PrimitiveObjectInspectorConverter.StringConverter(argumentOI); +evaluator = arg -> { + String val = (String) converter.convert(arg.get()); + applyBucketTransform(val, Types.StringType.get()); +}; +break; + + case BINARY: +converter = new PrimitiveObjectInspectorConverter.BinaryConverter(argumentOI, +
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735276&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735276 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 02/Mar/22 12:59 Start Date: 02/Mar/22 12:59 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r817666327 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHA
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=735272&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-735272 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 02/Mar/22 12:42 Start Date: 02/Mar/22 12:42 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r817654079 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHA
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734771&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734771 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:53 Start Date: 01/Mar/22 16:53 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816959131 ## File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ## @@ -8128,13 +8128,9 @@ private FileSinkDesc createFileSinkDesc(String dest, TableDesc table_desc, // Some non-native tables might be partitioned without partition spec information being present in the Table object HiveStorageHandler storageHandler = dest_tab.getStorageHandler(); if (storageHandler != null && storageHandler.alwaysUnpartitioned()) { -List nonNativePartSpecs = storageHandler.getPartitionTransformSpec(dest_tab); -if (dpCtx == null && nonNativePartSpecs != null && !nonNativePartSpecs.isEmpty()) { - verifyDynamicPartitionEnabled(conf, qb, dest); - Map partSpec = new LinkedHashMap<>(); - nonNativePartSpecs.forEach(ps -> partSpec.put(ps.getColumnName(), null)); - dpCtx = new DynamicPartitionCtx(partSpec, conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), - conf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +DynamicPartitionCtx nonNativeDpCtx = storageHandler.createDPContext(conf, dest_tab); +if (dpCtx == null && nonNativeDpCtx != null) { Review comment: That's right. It's because Hive doesn't know about partition column in Iceberg tables, so doesn't bother creating a dynamic partitioning context at all.. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734771) Time Spent: 5h (was: 4h 50m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734768&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734768 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:50 Start Date: 01/Mar/22 16:50 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816956834 ## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java ## @@ -521,34 +570,45 @@ private void inferSortPositions(Operator fsParent, } } -public ReduceSinkOperator getReduceSinkOp(List partitionPositions, -List sortPositions, List sortOrder, List sortNullOrder, -ArrayList allCols, ArrayList bucketColumns, int numBuckets, -Operator parent, AcidUtils.Operation writeType) throws SemanticException { +public ReduceSinkOperator getReduceSinkOp(List partitionPositions, List sortPositions, +List, ExprNodeDesc>> customSortExprs, List sortOrder, +List sortNullOrder, ArrayList allCols, ArrayList bucketColumns, +int numBuckets, Operator parent, AcidUtils.Operation writeType) { + + // Order of KEY columns, if custom sort is present partition and bucket columns are disregarded: + // 0) Custom sort expressions + // 1) Partition columns + // 2) Bucket number column Review comment: This one's deliberate. Wanted to emphasise it's either 0+3 or 1,2+3 -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734768) Time Spent: 4h 50m (was: 4h 40m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 4h 50m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734765&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734765 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:48 Start Date: 01/Mar/22 16:48 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816955075 ## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ## @@ -585,6 +585,13 @@ system.registerGenericUDF(GenericUDFMaskShowFirstN.UDF_NAME, GenericUDFMaskShowFirstN.class); system.registerGenericUDF(GenericUDFMaskShowLastN.UDF_NAME, GenericUDFMaskShowLastN.class); system.registerGenericUDF(GenericUDFMaskHash.UDF_NAME, GenericUDFMaskHash.class); + +try { + system.registerGenericUDF("iceberg_bucket", Review comment: It's easier to deploy like this, as the this way iceberg_bucket will be a built-in function (which it is). I've seen some problems with the availability of UDFs on LLAP for example.. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734765) Time Spent: 4h 40m (was: 4.5h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 4h 40m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734762&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734762 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:47 Start Date: 01/Mar/22 16:47 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816953758 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); + +DynamicPartitionCtx dpCtx = new DynamicPartitionCtx(new LinkedHashMap<>(), +hiveConf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), +hiveConf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +List, ExprNodeDesc>> customSortExprs = new LinkedList<>(); +dpCtx.setCustomSortExpressions(customSortExprs); + +Map fieldOrderMap = new HashMap<>(); +List fields = table.schema().columns(); +for (int i = 0; i < fields.size(); ++i) { + fieldOrderMap.put(fields.get(i).name(), i); +} + +for (PartitionTransformSpec spec : partitionTransformSpecs) { + int order = fieldOrderMap.get(spec.getColumnName()); Review comment: Sure, why not? Those expressions would just have the same source column. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734762) Time Spent: 4.5h (was: 4h 20m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 4.5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734760&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734760 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:44 Start Date: 01/Mar/22 16:44 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816951333 ## File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveStorageHandler.java ## @@ -280,6 +283,21 @@ default boolean supportsPartitionTransform() { return null; } + /** + * Creates a DynnamicPartitionCtx instance that will be set up by the storage handler itself. Useful for non-native + * tables where partitions are not handled by Hive, and sorting is required in a custom way before writing the table. Review comment: fixing javadoc -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734760) Time Spent: 4h 20m (was: 4h 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 4h 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734759&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734759 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:42 Start Date: 01/Mar/22 16:42 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816949566 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHA
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734758&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734758 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:41 Start Date: 01/Mar/22 16:41 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816948553 ## File path: ql/src/java/org/apache/hadoop/hive/ql/plan/DynamicPartitionCtx.java ## @@ -50,6 +52,14 @@ private String defaultPartName; // default partition name in case of null or empty value private int maxPartsPerNode;// maximum dynamic partitions created per mapper/reducer private Pattern whiteListPattern; + /** + * Expressions describing a custom way of sorting the table before write. Expressions can reference simple + * column descriptions or a tree of expressions containing more columns and UDFs. + * Can be useful for custom bucket/hash sorting. + * A custom expression should be a lambda that is given the original column description expressions as per read + * schema and returns a single expression. Example for simply just referencing column 3: cols -> cols.get(3).clone() + */ + private transient List, ExprNodeDesc>> customSortExpressions; Review comment: Yeah, I was wondering if it's okay if these expressions don't get to the executors. But I got my answer - Thanks! -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734758) Time Spent: 4h (was: 3h 50m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 4h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734757&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734757 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:40 Start Date: 01/Mar/22 16:40 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816946872 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) Review comment: just a leftover - removing it -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734757) Time Spent: 3h 50m (was: 3h 40m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 3h 50m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734756&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734756 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 16:39 Start Date: 01/Mar/22 16:39 Worklog Time Spent: 10m Work Description: szlta commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816946090 ## File path: ql/src/java/org/apache/hadoop/hive/ql/plan/DynamicPartitionCtx.java ## @@ -50,6 +52,14 @@ private String defaultPartName; // default partition name in case of null or empty value private int maxPartsPerNode;// maximum dynamic partitions created per mapper/reducer private Pattern whiteListPattern; + /** + * Expressions describing a custom way of sorting the table before write. Expressions can reference simple + * column descriptions or a tree of expressions containing more columns and UDFs. + * Can be useful for custom bucket/hash sorting. + * A custom expression should be a lambda that is given the original column description expressions as per read + * schema and returns a single expression. Example for simply just referencing column 3: cols -> cols.get(3).clone() + */ + private transient List, ExprNodeDesc>> customSortExpressions; Review comment: The job has the dpCtx serialized, and for some reason kryo is throwing exceptions for lambdas on the executor side. The expressions here are only needed in HS2 during query planning so I just prevent them from going to executors in the first place. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734756) Time Spent: 3h 40m (was: 3.5h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 3h 40m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734654&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734654 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 14:59 Start Date: 01/Mar/22 14:59 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816848964 ## File path: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ## @@ -8128,13 +8128,9 @@ private FileSinkDesc createFileSinkDesc(String dest, TableDesc table_desc, // Some non-native tables might be partitioned without partition spec information being present in the Table object HiveStorageHandler storageHandler = dest_tab.getStorageHandler(); if (storageHandler != null && storageHandler.alwaysUnpartitioned()) { -List nonNativePartSpecs = storageHandler.getPartitionTransformSpec(dest_tab); -if (dpCtx == null && nonNativePartSpecs != null && !nonNativePartSpecs.isEmpty()) { - verifyDynamicPartitionEnabled(conf, qb, dest); - Map partSpec = new LinkedHashMap<>(); - nonNativePartSpecs.forEach(ps -> partSpec.put(ps.getColumnName(), null)); - dpCtx = new DynamicPartitionCtx(partSpec, conf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), - conf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +DynamicPartitionCtx nonNativeDpCtx = storageHandler.createDPContext(conf, dest_tab); +if (dpCtx == null && nonNativeDpCtx != null) { Review comment: This means `dpCtx` does not get initialized at this point for Iceberg queries? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734654) Time Spent: 3.5h (was: 3h 20m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 3.5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734652&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734652 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 14:58 Start Date: 01/Mar/22 14:58 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816847425 ## File path: ql/src/java/org/apache/hadoop/hive/ql/plan/DynamicPartitionCtx.java ## @@ -50,6 +52,14 @@ private String defaultPartName; // default partition name in case of null or empty value private int maxPartsPerNode;// maximum dynamic partitions created per mapper/reducer private Pattern whiteListPattern; + /** + * Expressions describing a custom way of sorting the table before write. Expressions can reference simple + * column descriptions or a tree of expressions containing more columns and UDFs. + * Can be useful for custom bucket/hash sorting. + * A custom expression should be a lambda that is given the original column description expressions as per read + * schema and returns a single expression. Example for simply just referencing column 3: cols -> cols.get(3).clone() + */ + private transient List, ExprNodeDesc>> customSortExpressions; Review comment: Out of curiosity, why transient? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734652) Time Spent: 3h 20m (was: 3h 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 3h 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734630&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734630 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 14:38 Start Date: 01/Mar/22 14:38 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816827544 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); + +DynamicPartitionCtx dpCtx = new DynamicPartitionCtx(new LinkedHashMap<>(), Review comment: nit: Maps.newLinkedHashMap() -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734630) Time Spent: 3h 10m (was: 3h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 3h 10m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734621&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734621 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 14:30 Start Date: 01/Mar/22 14:30 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816819174 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + cas
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734545&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734545 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 12:31 Start Date: 01/Mar/22 12:31 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816726890 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + cas
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734543&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734543 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 12:27 Start Date: 01/Mar/22 12:27 Worklog Time Spent: 10m Work Description: marton-bod commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816723868 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); Review comment: nit: arguments also, maybe we should tell the user what those arguments are, i.e. (value, bucketCount)? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734500&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734500 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:50 Start Date: 01/Mar/22 10:50 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816657904 ## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java ## @@ -521,34 +570,45 @@ private void inferSortPositions(Operator fsParent, } } -public ReduceSinkOperator getReduceSinkOp(List partitionPositions, -List sortPositions, List sortOrder, List sortNullOrder, -ArrayList allCols, ArrayList bucketColumns, int numBuckets, -Operator parent, AcidUtils.Operation writeType) throws SemanticException { +public ReduceSinkOperator getReduceSinkOp(List partitionPositions, List sortPositions, +List, ExprNodeDesc>> customSortExprs, List sortOrder, +List sortNullOrder, ArrayList allCols, ArrayList bucketColumns, +int numBuckets, Operator parent, AcidUtils.Operation writeType) { + + // Order of KEY columns, if custom sort is present partition and bucket columns are disregarded: + // 0) Custom sort expressions + // 1) Partition columns + // 2) Bucket number column + // 3) Sort columns + + boolean customSortExprPresent = customSortExprs != null && !customSortExprs.isEmpty(); - // Order of KEY columns - // 1) Partition columns - // 2) Bucket number column - // 3) Sort columns Set keyColsPosInVal = Sets.newLinkedHashSet(); ArrayList keyCols = Lists.newArrayList(); List newSortOrder = Lists.newArrayList(); List newSortNullOrder = Lists.newArrayList(); + if (customSortExprPresent) { +partitionPositions = new ArrayList<>(); +bucketColumns = new ArrayList<>(); +numBuckets = -1; + } + keyColsPosInVal.addAll(partitionPositions); if (bucketColumns != null && !bucketColumns.isEmpty()) { keyColsPosInVal.add(-1); } keyColsPosInVal.addAll(sortPositions); + Review comment: nit: not needed -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734500) Time Spent: 2.5h (was: 2h 20m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 2.5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734499&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734499 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:50 Start Date: 01/Mar/22 10:50 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816657703 ## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java ## @@ -521,34 +570,45 @@ private void inferSortPositions(Operator fsParent, } } -public ReduceSinkOperator getReduceSinkOp(List partitionPositions, -List sortPositions, List sortOrder, List sortNullOrder, -ArrayList allCols, ArrayList bucketColumns, int numBuckets, -Operator parent, AcidUtils.Operation writeType) throws SemanticException { +public ReduceSinkOperator getReduceSinkOp(List partitionPositions, List sortPositions, +List, ExprNodeDesc>> customSortExprs, List sortOrder, +List sortNullOrder, ArrayList allCols, ArrayList bucketColumns, +int numBuckets, Operator parent, AcidUtils.Operation writeType) { + + // Order of KEY columns, if custom sort is present partition and bucket columns are disregarded: + // 0) Custom sort expressions + // 1) Partition columns + // 2) Bucket number column Review comment: nit: formatting -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734499) Time Spent: 2h 20m (was: 2h 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 2h 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734498&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734498 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:47 Start Date: 01/Mar/22 10:47 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816656105 ## File path: ql/src/java/org/apache/hadoop/hive/ql/optimizer/SortedDynPartitionOptimizer.java ## @@ -169,17 +182,27 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx procCtx, // unlink connection between FS and its parent Operator fsParent = fsOp.getParentOperators().get(0); - // if all dp columns got constant folded then disable this optimization - if (allStaticPartitions(fsParent, fsOp.getConf().getDynPartCtx())) { + DynamicPartitionCtx dpCtx = fsOp.getConf().getDynPartCtx(); + + ArrayList parentCols = Lists.newArrayList(fsParent.getSchema().getSignature()); + ArrayList allRSCols = Lists.newArrayList(); + for (ColumnInfo ci : parentCols) { +allRSCols.add(new ExprNodeColumnDesc(ci)); + } + + // if all dp columns / custom sort expressions got constant folded then disable this optimization + if (allStaticPartitions(fsParent, allRSCols, dpCtx)) { LOG.debug("Bailing out of sorted dynamic partition optimizer as all dynamic partition" + " columns got constant folded (static partitioning)"); return null; } - DynamicPartitionCtx dpCtx = fsOp.getConf().getDynPartCtx(); List partitionPositions = getPartitionPositions(dpCtx, fsParent.getSchema()); + LinkedList, ExprNodeDesc>> customSortExprs = + new LinkedList<>(dpCtx.getCustomSortExpressions()); Review comment: Nit: Lists.newLinkedList? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734498) Time Spent: 2h 10m (was: 2h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 2h 10m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734494&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734494 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:46 Start Date: 01/Mar/22 10:46 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816655367 ## File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveStorageHandler.java ## @@ -280,6 +283,21 @@ default boolean supportsPartitionTransform() { return null; } + /** + * Creates a DynnamicPartitionCtx instance that will be set up by the storage handler itself. Useful for non-native Review comment: nit: `DynnamicPartitionCtx`-> `DynamicPartitionCtx` -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734494) Time Spent: 2h (was: 1h 50m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 2h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734493&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734493 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:46 Start Date: 01/Mar/22 10:46 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816654862 ## File path: ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ## @@ -585,6 +585,13 @@ system.registerGenericUDF(GenericUDFMaskShowFirstN.UDF_NAME, GenericUDFMaskShowFirstN.class); system.registerGenericUDF(GenericUDFMaskShowLastN.UDF_NAME, GenericUDFMaskShowLastN.class); system.registerGenericUDF(GenericUDFMaskHash.UDF_NAME, GenericUDFMaskHash.class); + +try { + system.registerGenericUDF("iceberg_bucket", Review comment: What happens if we add the iceberg jar with the `ADD JAR` command? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734493) Time Spent: 1h 50m (was: 1h 40m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1h 50m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734491&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734491 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:44 Start Date: 01/Mar/22 10:44 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816653572 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); + +DynamicPartitionCtx dpCtx = new DynamicPartitionCtx(new LinkedHashMap<>(), +hiveConf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), +hiveConf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +List, ExprNodeDesc>> customSortExprs = new LinkedList<>(); +dpCtx.setCustomSortExpressions(customSortExprs); + +Map fieldOrderMap = new HashMap<>(); +List fields = table.schema().columns(); +for (int i = 0; i < fields.size(); ++i) { + fieldOrderMap.put(fields.get(i).name(), i); +} + +for (PartitionTransformSpec spec : partitionTransformSpecs) { + int order = fieldOrderMap.get(spec.getColumnName()); Review comment: Is it possible to create 2 transforms for a single column? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734491) Time Spent: 1h 40m (was: 1.5h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1h 40m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734487&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734487 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:34 Start Date: 01/Mar/22 10:34 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816645988 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); + +DynamicPartitionCtx dpCtx = new DynamicPartitionCtx(new LinkedHashMap<>(), +hiveConf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), +hiveConf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +List, ExprNodeDesc>> customSortExprs = new LinkedList<>(); +dpCtx.setCustomSortExpressions(customSortExprs); + +Map fieldOrderMap = new HashMap<>(); Review comment: Nit: Maps.newHashMap() -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734487) Time Spent: 1.5h (was: 1h 20m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1.5h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734486&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734486 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 10:34 Start Date: 01/Mar/22 10:34 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816645719 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse +List partitionTransformSpecs = getPartitionTransformSpec(hmsTable); + +DynamicPartitionCtx dpCtx = new DynamicPartitionCtx(new LinkedHashMap<>(), +hiveConf.getVar(HiveConf.ConfVars.DEFAULTPARTITIONNAME), +hiveConf.getIntVar(HiveConf.ConfVars.DYNAMICPARTITIONMAXPARTSPERNODE)); +List, ExprNodeDesc>> customSortExprs = new LinkedList<>(); Review comment: Nit: Lists.newLinkedList() -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734486) Time Spent: 1h 20m (was: 1h 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1h 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734443&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734443 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:59 Start Date: 01/Mar/22 08:59 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816568606 ## File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveStorageHandler.java ## @@ -280,6 +283,21 @@ default boolean supportsPartitionTransform() { return null; } + /** + * Creates a DynnamicPartitionCtx instance that will be set up by the storage handler itself. Useful for non-native + * tables where partitions are not handled by Hive, and sorting is required in a custom way before writing the table. Review comment: What happens if the return value is `null` -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734443) Time Spent: 1h 10m (was: 1h) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1h 10m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734442&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734442 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:56 Start Date: 01/Mar/22 08:56 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816565844 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -307,6 +328,41 @@ public boolean supportsPartitionTransform() { }).collect(Collectors.toList()); } + @Override + public DynamicPartitionCtx createDPContext(HiveConf hiveConf, org.apache.hadoop.hive.ql.metadata.Table hmsTable) + throws SemanticException { +TableDesc tableDesc = Utilities.getTableDesc(hmsTable); +Table table = IcebergTableUtil.getTable(conf, tableDesc.getProperties()); +if (table.spec().isUnpartitioned()) { + return null; +} +// Iceberg currently doesn't have publicly accessible partition transform information, hence use above string parse Review comment: nit: newline -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734442) Time Spent: 1h (was: 50m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 1h > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734441&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734441 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:55 Start Date: 01/Mar/22 08:55 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816565009 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java ## @@ -96,6 +104,20 @@ private static final String ICEBERG_URI_PREFIX = "iceberg://"; private static final Splitter TABLE_NAME_SPLITTER = Splitter.on(".."); private static final String TABLE_NAME_SEPARATOR = ".."; + private static final transient BiFunction, ExprNodeDesc>> Review comment: nit: Comment please -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734441) Time Spent: 50m (was: 40m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 50m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734440&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734440 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:53 Start Date: 01/Mar/22 08:53 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816564026 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHA
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734438&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734438 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:50 Start Date: 01/Mar/22 08:50 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816561376 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) +public class GenericUDFIcebergBucket extends GenericUDF { + private final IntWritable result = new IntWritable(); + private transient PrimitiveObjectInspector argumentOI; + private transient PrimitiveObjectInspectorConverter.StringConverter stringConverter; + private transient PrimitiveObjectInspectorConverter.BinaryConverter binaryConverter; + private transient PrimitiveObjectInspectorConverter.IntConverter intConverter; + private transient PrimitiveObjectInspectorConverter.LongConverter longConverter; + private transient PrimitiveObjectInspectorConverter.HiveDecimalConverter decimalConverter; + private transient PrimitiveObjectInspectorConverter.FloatConverter floatConverter; + private transient PrimitiveObjectInspectorConverter.DoubleConverter doubleConverter; + private transient Type.PrimitiveType icebergType; + private int numBuckets = -1; + + @Override + public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { +if (arguments.length != 2) { + throw new UDFArgumentLengthException( + "ICEBERG_BUCKET requires 2 argument, got " + arguments.length); +} + +if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { + throw new UDFArgumentException( + "ICEBERG_BUCKET first argument takes primitive types, got " + argumentOI.getTypeName()); +} +argumentOI = (PrimitiveObjectInspector) arguments[0]; + +PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory(); +ObjectInspector outputOI = null; +switch (inputType) { + case CHA
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=734433&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-734433 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 01/Mar/22 08:43 Start Date: 01/Mar/22 08:43 Worklog Time Spent: 10m Work Description: pvary commented on a change in pull request #3060: URL: https://github.com/apache/hive/pull/3060#discussion_r816556254 ## File path: iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/GenericUDFIcebergBucket.java ## @@ -0,0 +1,209 @@ +/* + * 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.iceberg.mr.hive; + +import java.nio.ByteBuffer; +import org.apache.hadoop.hive.ql.exec.Description; +import org.apache.hadoop.hive.ql.exec.UDFArgumentException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException; +import org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException; +import org.apache.hadoop.hive.ql.metadata.HiveException; +import org.apache.hadoop.hive.ql.udf.generic.GenericUDF; +import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorConverter; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableConstantIntObjectInspector; +import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils; +import org.apache.hadoop.io.BytesWritable; +import org.apache.hadoop.io.DoubleWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.iceberg.transforms.Transform; +import org.apache.iceberg.transforms.Transforms; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +/** + * GenericUDFIcebergBucket - UDF that wraps around Iceberg's bucket transform function + */ +@Description(name = "iceberg_bucket", +value = "_FUNC_(value, bucketCount) - " + +"Returns the bucket value calculated by Iceberg bucket transform function ", +extended = "Example:\n > SELECT _FUNC_('A bucket full of ice!', 5);\n 4") +//@VectorizedExpressions({StringLength.class}) Review comment: nit: Why is this commented out? Shall we just remove it? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 734433) Time Spent: 20m (was: 10m) > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Labels: pull-request-available > Time Spent: 20m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)
[jira] [Work logged] (HIVE-25975) Optimize ClusteredWriter for bucketed Iceberg tables
[ https://issues.apache.org/jira/browse/HIVE-25975?focusedWorklogId=733981&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-733981 ] ASF GitHub Bot logged work on HIVE-25975: - Author: ASF GitHub Bot Created on: 28/Feb/22 16:48 Start Date: 28/Feb/22 16:48 Worklog Time Spent: 10m Work Description: szlta opened a new pull request #3060: URL: https://github.com/apache/hive/pull/3060 This adds a new UDF that uses Iceberg's bucket transformation function to produce bucket values from constants or any column input. All types that Iceberg buckets support are supported in this UDF too, except for UUID. This UDF is then used in SortedDynPartitionOptimizer to sort data during write if the target Iceberg target has bucket transform partitioning. To enable this, Hive has been extended with the feature that allows storage handlers to define custom sorting expressions, to be passed to FileSink operator's DynPartContext during dynamic partitioning write scenarios. The lenient version of ClusteredWriter in patched-iceberg-core has been disposed of as it is not needed anymore with this feature in. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking --- Worklog Id: (was: 733981) Remaining Estimate: 0h Time Spent: 10m > Optimize ClusteredWriter for bucketed Iceberg tables > > > Key: HIVE-25975 > URL: https://issues.apache.org/jira/browse/HIVE-25975 > Project: Hive > Issue Type: Improvement >Reporter: Ádám Szita >Assignee: Ádám Szita >Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > The first version of the ClusteredWriter in Hive-Iceberg will be lenient for > bucketed tables: i.e. the records do not need to be ordered by the bucket > values, the writer will just close its current file and open a new one for > out-of-order records. > This is suboptimal for the long-term due to creating many small files. Spark > uses a UDF to compute the bucket value for each record and therefore it is > able to order the records by bucket values, achieving optimal clustering. -- This message was sent by Atlassian Jira (v8.20.1#820001)