Github user QiangCai commented on a diff in the pull request:

    
https://github.com/apache/incubator-carbondata/pull/672#discussion_r107886267
  
    --- Diff: 
integration/hive/src/main/java/org/apache/carbondata/hive/CarbonHiveSerDe.java 
---
    @@ -0,0 +1,232 @@
    +/*
    + * 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.carbondata.hive;
    +
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Properties;
    +import javax.annotation.Nullable;
    +
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.hive.serde.serdeConstants;
    +import org.apache.hadoop.hive.serde2.AbstractSerDe;
    +import org.apache.hadoop.hive.serde2.SerDeException;
    +import org.apache.hadoop.hive.serde2.SerDeSpec;
    +import org.apache.hadoop.hive.serde2.SerDeStats;
    +import org.apache.hadoop.hive.serde2.io.DoubleWritable;
    +import org.apache.hadoop.hive.serde2.io.ShortWritable;
    +import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
    +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
    +import org.apache.hadoop.hive.serde2.objectinspector.StructField;
    +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.DateObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.HiveDecimalObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector;
    +import 
org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector;
    +import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo;
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
    +import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
    +import org.apache.hadoop.io.ArrayWritable;
    +import org.apache.hadoop.io.IntWritable;
    +import org.apache.hadoop.io.LongWritable;
    +import org.apache.hadoop.io.Writable;
    +
    +
    +/**
    + * A serde class for Carbondata.
    + * It transparently passes the object to/from the Carbon file 
reader/writer.
    + */
    +@SerDeSpec(schemaProps = {serdeConstants.LIST_COLUMNS, 
serdeConstants.LIST_COLUMN_TYPES})
    +public class CarbonHiveSerDe extends AbstractSerDe {
    +  private SerDeStats stats;
    +  private ObjectInspector objInspector;
    +
    +  private enum LAST_OPERATION {
    +    SERIALIZE,
    +    DESERIALIZE,
    +    UNKNOWN
    +  }
    +
    +  private LAST_OPERATION status;
    +  private long serializedSize;
    +  private long deserializedSize;
    +
    +  public CarbonHiveSerDe() {
    +    stats = new SerDeStats();
    +  }
    +
    +  @Override
    +  public void initialize(@Nullable Configuration configuration, Properties 
tbl)
    +      throws SerDeException {
    +
    +    final TypeInfo rowTypeInfo;
    +    final List<String> columnNames;
    +    final List<TypeInfo> columnTypes;
    +    // Get column names and sort order
    +    final String columnNameProperty = 
tbl.getProperty(serdeConstants.LIST_COLUMNS);
    +    final String columnTypeProperty = 
tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES);
    +
    +    if (columnNameProperty.length() == 0) {
    +      columnNames = new ArrayList<String>();
    +    } else {
    +      columnNames = Arrays.asList(columnNameProperty.split(","));
    +    }
    +    if (columnTypeProperty.length() == 0) {
    +      columnTypes = new ArrayList<TypeInfo>();
    +    } else {
    +      columnTypes = 
TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty);
    +    }
    +    // Create row related objects
    +    rowTypeInfo = TypeInfoFactory.getStructTypeInfo(columnNames, 
columnTypes);
    +    this.objInspector = new CarbonObjectInspector((StructTypeInfo) 
rowTypeInfo);
    +
    +    // Stats part
    +    serializedSize = 0;
    +    deserializedSize = 0;
    +    status = LAST_OPERATION.UNKNOWN;
    +  }
    +
    +  @Override
    +  public Class<? extends Writable> getSerializedClass() {
    +    return ArrayWritable.class;
    +  }
    +
    +  @Override
    +  public Writable serialize(Object obj, ObjectInspector objectInspector) 
throws SerDeException {
    +    if 
(!objInspector.getCategory().equals(ObjectInspector.Category.STRUCT)) {
    +      throw new SerDeException("Cannot serialize " + 
objInspector.getCategory()
    +        + ". Can only serialize a struct");
    +    }
    +    serializedSize += ((StructObjectInspector) 
objInspector).getAllStructFieldRefs().size();
    +    status = LAST_OPERATION.SERIALIZE;
    +    ArrayWritable serializeData = createStruct(obj, 
(StructObjectInspector) objInspector);
    +    return serializeData;
    --- End diff --
    
    return createStruct directly.


---
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.
---

Reply via email to