KurtYoung commented on a change in pull request #10022: 
[FLINK-14135][hive][orc] Introduce orc ColumnarRow reader for hive connector
URL: https://github.com/apache/flink/pull/10022#discussion_r352436580
 
 

 ##########
 File path: 
flink-formats/flink-orc/src/main/java/org/apache/flink/orc/vector/AbstractOrcColumnVector.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.flink.orc.vector;
+
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
+
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+
+import static 
org.apache.flink.table.runtime.functions.SqlDateTimeUtils.dateToInternal;
+
+/**
+ * This column vector is used to adapt hive's ColumnVector to Flink's 
ColumnVector.
+ */
+public abstract class AbstractOrcColumnVector implements
+               org.apache.flink.table.dataformat.vector.ColumnVector {
+
+       private ColumnVector vector;
+
+       AbstractOrcColumnVector(ColumnVector vector) {
+               this.vector = vector;
+       }
+
+       @Override
+       public boolean isNullAt(int i) {
+               return !vector.noNulls && vector.isNull[vector.isRepeating ? 0 
: i];
+       }
+
+       @Override
+       public void reset() {
+               throw new UnsupportedOperationException();
+       }
+
+       public static org.apache.flink.table.dataformat.vector.ColumnVector 
createVector(
+                       ColumnVector vector) {
+               if (vector instanceof LongColumnVector) {
+                       return new OrcLongColumnVector((LongColumnVector) 
vector);
+               } else if (vector instanceof DoubleColumnVector) {
+                       return new OrcDoubleColumnVector((DoubleColumnVector) 
vector);
+               } else if (vector instanceof BytesColumnVector) {
+                       return new OrcBytesColumnVector((BytesColumnVector) 
vector);
+               } else if (vector instanceof DecimalColumnVector) {
+                       return new OrcDecimalColumnVector((DecimalColumnVector) 
vector);
+               } else if (vector instanceof TimestampColumnVector) {
+                       return new 
OrcTimestampColumnVector((TimestampColumnVector) vector);
+               } else {
+                       throw new UnsupportedOperationException("Unsupport 
vector: " + vector.getClass().getName());
+               }
+       }
+
+       /**
+        * Create flink vector by hive vector from constant.
+        */
+       public static org.apache.flink.table.dataformat.vector.ColumnVector 
createVectorFromConstant(
+                       LogicalType type, Object value, int batchSize) {
+               return createVector(createHiveVectorFromConstant(type, value, 
batchSize));
+       }
+
+       /**
+        * Create a orc vector from partition spec value.
+        * See hive {@code VectorizedRowBatchCtx#addPartitionColsToBatch}.
+        */
+       private static ColumnVector createHiveVectorFromConstant(
+                       LogicalType type, Object value, int batchSize) {
+               switch (type.getTypeRoot()) {
+                       case CHAR:
+                       case VARCHAR:
+                       case BINARY:
+                       case VARBINARY:
+                               return createBytesVector(batchSize, value);
+                       case BOOLEAN:
+                               return createLongVector(batchSize, (Boolean) 
value ? 1 : 0);
+                       case TINYINT:
+                       case SMALLINT:
+                       case INTEGER:
+                       case BIGINT:
+                               return createLongVector(batchSize, value);
+                       case DECIMAL:
+                               DecimalType decimalType = (DecimalType) type;
+                               return createDecimalVector(
+                                               batchSize, 
decimalType.getPrecision(), decimalType.getScale(), value);
+                       case FLOAT:
+                       case DOUBLE:
+                               return createDoubleVector(batchSize, value);
+                       case DATE:
+                               return createLongVector(batchSize, 
dateToInternal((Date) value));
+                       case TIMESTAMP_WITHOUT_TIME_ZONE:
+                               return createTimestampVector(batchSize, 
(LocalDateTime) value);
+                       default:
+                               throw new 
UnsupportedOperationException("Unsupported type: " + type);
+               }
+       }
+
+       private static LongColumnVector createLongVector(int batchSize, Object 
value) {
+               LongColumnVector lcv = new LongColumnVector(batchSize);
 
 Review comment:
   I read the source code, and actually `fill` only set the first element and 
will also set `isRepeated` to `true`. In this case, other fields will be 
`NULL`, sounds acceptable to me.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to