Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for top-level comments, bumped version number.

  • Loading branch information...
commit 29ead1fe101baafa8e9844eaf92022cbe4846c6f 1 parent ac9e7d9
@jghoman authored
View
2  pom.xml
@@ -5,7 +5,7 @@
<groupId>com.linkedin</groupId>
<artifactId>haivvreo</artifactId>
<packaging>jar</packaging>
- <version>1.0.10-avro14-hive8-SNAPSHOT</version>
+ <version>1.0.11-avro14-hive8-SNAPSHOT</version>
<name>haivvreo</name>
<url>https://github.com/jghoman/haivvreo</url>
<description>Library for processing Avro data in Hive.</description>
View
28 src/main/java/com/linkedin/haivvreo/AvroObjectInspectorGenerator.java
@@ -21,7 +21,12 @@
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
-import org.apache.hadoop.hive.serde2.typeinfo.*;
+import org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.UnionTypeInfo;
import java.util.ArrayList;
import java.util.List;
@@ -36,6 +41,7 @@
class AvroObjectInspectorGenerator {
final private List<String> columnNames;
final private List<TypeInfo> columnTypes;
+ final private List<String> columnComments;
final private ObjectInspector oi;
public AvroObjectInspectorGenerator(Schema schema) throws SerDeException {
@@ -43,6 +49,7 @@ public AvroObjectInspectorGenerator(Schema schema) throws SerDeException {
this.columnNames = generateColumnNames(schema);
this.columnTypes = SchemaToTypeInfo.generateColumnTypes(schema);
+ this.columnComments = generateColumnComments(schema);
assert columnNames.size() == columnTypes.size();
this.oi = createObjectInspector();
}
@@ -61,6 +68,10 @@ private void verifySchemaIsARecord(Schema schema) throws SerDeException {
return columnTypes;
}
+ public List<String> getColumnComments() {
+ return columnComments;
+ }
+
public ObjectInspector getObjectInspector() {
return oi;
}
@@ -72,7 +83,8 @@ private ObjectInspector createObjectInspector() throws SerDeException {
for(int i = 0; i < columnNames.size(); i++) {
columnOIs.add(i, createObjectInspectorWorker(columnTypes.get(i)));
}
- return ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, columnOIs);
+
+ return ObjectInspectorFactory.getStandardStructObjectInspector(columnNames, columnOIs, columnComments);
}
private ObjectInspector createObjectInspectorWorker(TypeInfo ti) throws SerDeException {
@@ -144,4 +156,16 @@ private boolean supportedCategories(TypeInfo ti) {
return fieldsList;
}
+ private List<String> generateColumnComments(Schema schema) {
+ List<Schema.Field> fields = schema.getFields();
+ List<String> comments = new ArrayList<String>(fields.size());
+
+ for (Schema.Field field : fields) {
+ String comment = field.doc();
+ if(comment == null) comment = "";
+ comments.add(comment);
+ }
+
+ return comments;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.