Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/74#discussion_r29096976 --- Diff: phoenix-hive/src/main/java/org/apache/phoenix/hive/util/HiveTypeUtil.java --- @@ -0,0 +1,151 @@ +/* + * Copyright 2010 The Apache Software Foundation Licensed to the Apache Software Foundation (ASF) + * under one or more contributor license agreements. See the NOTICE filedistributed 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 maynot 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 applicablelaw 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.phoenix.hive.util; + +import java.sql.Date; +import java.sql.Timestamp; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hive.common.type.HiveChar; +import org.apache.hadoop.hive.common.type.HiveVarchar; +import org.apache.hadoop.hive.serde2.SerDeException; +import org.apache.hadoop.hive.serde2.io.DateWritable; +import org.apache.hadoop.hive.serde2.io.DoubleWritable; +import org.apache.hadoop.hive.serde2.io.HiveCharWritable; +import org.apache.hadoop.hive.serde2.io.HiveVarcharWritable; +import org.apache.hadoop.hive.serde2.io.ShortWritable; +import org.apache.hadoop.hive.serde2.io.TimestampWritable; +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo; +import org.apache.hadoop.io.BooleanWritable; +import org.apache.hadoop.io.FloatWritable; +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.LongWritable; +import org.apache.hadoop.io.Text; +import org.apache.hadoop.io.Writable; +import org.apache.phoenix.schema.types.PBinary; +import org.apache.phoenix.schema.types.PBoolean; +import org.apache.phoenix.schema.types.PChar; +import org.apache.phoenix.schema.types.PDataType; +import org.apache.phoenix.schema.types.PDate; +import org.apache.phoenix.schema.types.PDouble; +import org.apache.phoenix.schema.types.PFloat; +import org.apache.phoenix.schema.types.PInteger; +import org.apache.phoenix.schema.types.PLong; +import org.apache.phoenix.schema.types.PSmallint; +import org.apache.phoenix.schema.types.PTime; +import org.apache.phoenix.schema.types.PTimestamp; +import org.apache.phoenix.schema.types.PVarchar; + +public class HiveTypeUtil { + private static final Log LOG = LogFactory.getLog(HiveTypeUtil.class); + + private HiveTypeUtil() { + } + + /** + * This method returns an array of most appropriates PDataType associated with a list of + * incoming hive types. + * @param List of TypeInfo + * @return Array PDataType + */ + public static PDataType[] hiveTypesToSqlTypes(List<TypeInfo> columnTypes) throws SerDeException { + final PDataType[] result = new PDataType[columnTypes.size()]; + for (int i = 0; i < columnTypes.size(); i++) { + result[i] = HiveType2PDataType(columnTypes.get(i)); + } + return result; + } + + /** + * This method returns the most appropriate PDataType associated with the incoming primitive + * hive type. + * @param hiveType + * @return PDataType + */ + public static PDataType HiveType2PDataType(TypeInfo hiveType) throws SerDeException { + switch (hiveType.getCategory()) { + /* Integrate Complex types like Array */ + case PRIMITIVE: + return HiveType2PDataType(hiveType.getTypeName()); + default: + throw new SerDeException("Phoenix unsupported column type: " + + hiveType.getCategory().name()); + } + } + + /** + * This method returns the most appropriate PDataType associated with the incoming hive type + * name. + * @param hiveType + * @return PDataType + */ + public static PDataType HiveType2PDataType(String hiveType) throws SerDeException { + final String lctype = hiveType.toLowerCase(); + if ("string".equals(lctype)) { --- End diff -- Looks like the same as the earlier one?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---