liyafan82 commented on code in PR #13589: URL: https://github.com/apache/arrow/pull/13589#discussion_r927500029
########## java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java: ########## @@ -0,0 +1,263 @@ +/* + * 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.arrow.adapter.jdbc.binder; + +import java.sql.Types; +import java.time.ZoneId; +import java.util.Calendar; +import java.util.TimeZone; + +import org.apache.arrow.vector.BigIntVector; +import org.apache.arrow.vector.BitVector; +import org.apache.arrow.vector.DateDayVector; +import org.apache.arrow.vector.DateMilliVector; +import org.apache.arrow.vector.Decimal256Vector; +import org.apache.arrow.vector.DecimalVector; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.FixedSizeBinaryVector; +import org.apache.arrow.vector.Float4Vector; +import org.apache.arrow.vector.Float8Vector; +import org.apache.arrow.vector.IntVector; +import org.apache.arrow.vector.LargeVarBinaryVector; +import org.apache.arrow.vector.LargeVarCharVector; +import org.apache.arrow.vector.SmallIntVector; +import org.apache.arrow.vector.TimeMicroVector; +import org.apache.arrow.vector.TimeMilliVector; +import org.apache.arrow.vector.TimeNanoVector; +import org.apache.arrow.vector.TimeSecVector; +import org.apache.arrow.vector.TimeStampVector; +import org.apache.arrow.vector.TinyIntVector; +import org.apache.arrow.vector.VarBinaryVector; +import org.apache.arrow.vector.VarCharVector; +import org.apache.arrow.vector.types.pojo.ArrowType; + +/** + * Visitor to create the base ColumnBinder for a vector. + * <p> + * To handle null values, wrap the returned binder in a {@link NullableColumnBinder}. + */ +public class ColumnBinderArrowTypeVisitor implements ArrowType.ArrowTypeVisitor<ColumnBinder> { + private final FieldVector vector; + private final Integer jdbcType; + + /** + * Create a binder using a custom JDBC type code. + * + * @param vector The vector that the binder will wrap. + * @param jdbcType The JDBC type code (or null to use the default). + */ + public ColumnBinderArrowTypeVisitor(FieldVector vector, Integer jdbcType) { + this.vector = vector; + this.jdbcType = jdbcType; + } + + @Override + public ColumnBinder visit(ArrowType.Null type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.Struct type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.List type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.LargeList type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.FixedSizeList type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.Union type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.Map type) { + throw new UnsupportedOperationException("No column binder implemented for type " + type); + } + + @Override + public ColumnBinder visit(ArrowType.Int type) { + switch (type.getBitWidth()) { + case 8: + if (type.getIsSigned()) { + return jdbcType == null ? new TinyIntBinder((TinyIntVector) vector) : + new TinyIntBinder((TinyIntVector) vector, jdbcType); + } else { + throw new UnsupportedOperationException( Review Comment: Maybe we can extract this statement for all type widths, at the beginning of this method? -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org