wankunde commented on code in PR #41782:
URL: https://github.com/apache/spark/pull/41782#discussion_r1294423164
##########
sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java:
##########
@@ -84,6 +84,8 @@ final class ParquetColumnVector {
if (defaultValue == null) {
vector.setAllNull();
return;
+ } else {
+ vector.setHasDefaultValue();
Review Comment:
Before this PR, there is no existing bug, after this PR, for Parquet tables
whose columns have associated DEFAULT values, the result may be incorrect.
https://github.com/apache/spark/blob/master/sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/ParquetColumnVector.java#L84C15-L100
So I add a flag `protected boolean hasDefaultValue = false;` to indicate if
the current column vector has default value and not to clean the data if it's
true.
##########
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/VectorReservePolicy.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.spark.sql.execution.vectorized;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.unsafe.array.ByteArrayMethods;
+
+public abstract class VectorReservePolicy {
Review Comment:
OK, I'll inline the policy logic.
And do you think we should track the previously allocated memory size?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -487,6 +487,25 @@ object SQLConf {
.intConf
.createWithDefault(10000)
+ val VECTORIZED_HUGE_VECTOR_RESERVE_RATIO =
+ buildConf("spark.sql.inMemoryColumnarStorage.hugeVectorReserveRatio")
+ .doc("spark will reserve requiredCapacity * this ratio memory next time.
This is only " +
+ "effective when spark.sql.inMemoryColumnarStorage.hugeVectorThreshold
> 0 and required " +
+ "memory larger than that threshold.")
+ .version("3.5.0")
+ .doubleConf
+ .createWithDefault(1.2)
+
+ val VECTORIZED_HUGE_VECTOR_THRESHOLD =
+ buildConf("spark.sql.inMemoryColumnarStorage.hugeVectorThreshold")
+ .doc("When the in memory column vector is larger than this, spark will
reserve " +
+ s"requiredCapacity * ${VECTORIZED_HUGE_VECTOR_RESERVE_RATIO.key}
memory next time and " +
+ "free this column vector before reading next batch data. -1 means
disabling the " +
+ "optimization.")
+ .version("3.5.0")
+ .intConf
Review Comment:
OK
##########
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/VectorReservePolicy.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.spark.sql.execution.vectorized;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.spark.sql.internal.SQLConf;
+import org.apache.spark.unsafe.array.ByteArrayMethods;
+
+public abstract class VectorReservePolicy {
+
+ protected int defaultCapacity;
+
+ /**
+ * Upper limit for the maximum capacity for this column.
+ */
+ @VisibleForTesting
+ protected int MAX_CAPACITY = ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH;
+
+ /**
+ * True if this column has default values. Return the default values instead
of NULL when the
+ * corresponding columns are not present in storage. We can not reset the
data of column vectors
+ * that has default values.
Review Comment:
The default value was set into the columnVector before reading data.
The default value is in ParquetColumnVector and it's internal vector `final
WritableColumnVector vector` does not know the default value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]