hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhr...@apache.org
Subject svn commit: r696525 [2/2] - in /hadoop/core/trunk: ./ src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/ src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ src/contrib/hive/serde/src/test/org/apache/hadoop/hive/s...
Date Thu, 18 Sep 2008 00:09:19 GMT
Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ReflectionStructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ReflectionStructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ReflectionStructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ReflectionStructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,138 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * ReflectionStructObjectInspector works on struct data that is stored as a native Java object.
+ * It will drill down into the Java class to get the fields and construct ObjectInspectors for 
+ * the fields, if they are not specified.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ *
+ */
+public class ReflectionStructObjectInspector implements StructObjectInspector {
+
+  public static class MyField implements StructField {
+    protected Field field;
+    protected ObjectInspector fieldObjectInspector;
+    
+    public MyField(Field field, ObjectInspector fieldObjectInspector) {
+      this.field = field;
+      this.fieldObjectInspector = fieldObjectInspector;
+    }
+    public String getFieldName() {
+      return field.getName().toLowerCase();
+    }
+    public ObjectInspector getFieldObjectInspector() {
+      return fieldObjectInspector;
+    }
+    public String toString() {
+      return field.toString();
+    }
+  }
+
+  Class<?> objectClass;
+  List<MyField> fields;
+  
+  public ReflectionStructObjectInspector(Class<?> objectClass, List<ObjectInspector> structFieldObjectInspectors) {
+    init(objectClass, structFieldObjectInspectors);
+  }
+
+  public Category getCategory() {
+    return Category.STRUCT;
+  }
+
+  public String getTypeName() {
+    return objectClass.getName();
+  }
+  
+  /**
+   * This method is only intended to be used by Utilities class in this package.
+   */
+  ReflectionStructObjectInspector() {
+  }
+  
+  /**
+   * This method is only intended to be used by Utilities class in this package.
+   * The reason that this method is not recursive by itself is because we want to allow
+   * recursive types.
+   */
+  void init(Class<?> objectClass, List<ObjectInspector> structFieldObjectInspectors) {
+    assert(!List.class.isAssignableFrom(objectClass));
+    assert(!Map.class.isAssignableFrom(objectClass));
+    
+    this.objectClass = objectClass;
+    Field[] reflectionFields = objectClass.getDeclaredFields();
+    fields = new ArrayList<MyField>(structFieldObjectInspectors.size());
+    int used = 0;
+    for (int i=0; i<reflectionFields.length; i++) {
+      if (!shouldIgnoreField(reflectionFields[i].getName())) {
+        fields.add(new MyField(reflectionFields[i], structFieldObjectInspectors.get(used++)));
+      }
+    }
+    assert(fields.size() == structFieldObjectInspectors.size());
+  }
+  
+  // ThriftStructObjectInspector will override and ignore __isset fields. 
+  public boolean shouldIgnoreField(String name) {
+    return false;
+  }
+  
+  // Without Data
+  public StructField getStructFieldRef(String fieldName) {
+    return ObjectInspectorUtils.getStandardStructFieldRef(fieldName, fields);
+  }
+  public List<? extends StructField> getAllStructFieldRefs() {
+    return fields;
+  }
+
+  // With Data
+  public Object getStructFieldData(Object data, StructField fieldRef) {
+    if (data == null) {
+      return null;
+    }
+    try {
+      MyField f = (MyField) fieldRef;
+      return f.field.get(data);
+    } catch (Exception e) {
+      throw new RuntimeException(e); 
+    }
+  }
+  public List<Object> getStructFieldsDataAsList(Object data) {
+    if (data == null) {
+      return null;
+    }
+    try {
+      ArrayList<Object> result = new ArrayList<Object>(fields.size());
+      for(int i=0; i<fields.size(); i++) {
+        result.add(fields.get(i).field.get(data));
+      }
+      return result;
+    } catch (Exception e) {
+      throw new RuntimeException(e); 
+    }
+  }
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardListObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardListObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardListObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardListObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,77 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.List;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+
+/**
+ * DefaultListObjectInspector works on list data that is stored as a Java List or Java Array object.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+class StandardListObjectInspector implements ListObjectInspector {
+
+  ObjectInspector listElementObjectInspector;
+  
+  /** Call ObjectInspectorFactory.getStandardListObjectInspector instead.
+   */
+  protected StandardListObjectInspector(ObjectInspector listElementObjectInspector) {
+    this.listElementObjectInspector = listElementObjectInspector;
+  }
+
+  public final Category getCategory() {
+    return Category.LIST;
+  }
+
+  // without data
+  public ObjectInspector getListElementObjectInspector() {
+    return listElementObjectInspector;
+  }
+  
+  // with data
+  public Object getListElement(Object data, int index) {
+    List<?> list = getList(data);
+    if (list == null || index < 0 || index >= list.size()) {
+      return null;
+    }
+    return list.get(index);
+  }
+  
+  public int getListLength(Object data) {
+    List<?> list = getList(data);
+    if (list == null) return -1;
+    return list.size();
+  }
+  
+  public List<?> getList(Object data) {
+    if (data == null) return null;
+    if (data.getClass().isArray()) {
+      data = java.util.Arrays.asList((Object[])data);
+    }
+    List<?> list = (List<?>) data;
+    return list;
+  }
+
+  public String getTypeName() {
+    return "list<" + listElementObjectInspector.getTypeName() + ">";
+  }
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardMapObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardMapObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardMapObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardMapObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,82 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.Map;
+
+/**
+ * StandardMapObjectInspector works on map data that is stored as a Java Map object.
+ * Note: the key object of the map must support equals and hashCode by itself.
+ * 
+ * We also plan to have a GeneralMapObjectInspector which can work on map with 
+ * key objects that does not support equals and hashCode.  That will require us to 
+ * store InspectableObject as the key, which will have overridden equals and hashCode 
+ * methods.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+class StandardMapObjectInspector implements MapObjectInspector {
+
+  ObjectInspector mapKeyObjectInspector;
+  ObjectInspector mapValueObjectInspector;
+  
+  /** Call ObjectInspectorFactory.getStandardMapObjectInspector instead.
+   */
+  protected StandardMapObjectInspector(ObjectInspector mapKeyObjectInspector, ObjectInspector mapValueObjectInspector) {
+    this.mapKeyObjectInspector = mapKeyObjectInspector;
+    this.mapValueObjectInspector = mapValueObjectInspector;
+  }
+
+  // without data
+  public ObjectInspector getMapKeyObjectInspector() {
+    return mapKeyObjectInspector;
+  }
+  public ObjectInspector getMapValueObjectInspector() {
+    return mapValueObjectInspector;
+  }
+
+  // with data
+  // TODO: Now we assume the key Object supports hashCode and equals functions.
+  public Object getMapValueElement(Object data, Object key) {
+    if (data == null || key == null) return null;
+    Map<?,?> map = (Map<?,?>)data;
+    return map.get(key);
+  }
+  int getMapSize(Object data) {
+    if (data == null) return -1;
+    Map<?,?> map = (Map<?,?>)data;
+    return map.size();
+  }
+  public Map<?,?> getMap(Object data) {
+    if (data == null) return null;
+    Map<?,?> map = (Map<?,?>)data;
+    return map;
+  }
+
+  public final Category getCategory() {
+    return Category.MAP;
+  }
+
+  public String getTypeName() {
+    return "map<" + mapKeyObjectInspector.getTypeName() + "," 
+        + mapValueObjectInspector.getTypeName() + ">";
+  }
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardPrimitiveObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardPrimitiveObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardPrimitiveObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardPrimitiveObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,49 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+/**
+ * PrimitiveObjectInspector works on primitive data that is stored as a Primitive Java object.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+class StandardPrimitiveObjectInspector implements PrimitiveObjectInspector {
+
+  Class<?> primitiveClass;
+  
+  /** Call ObjectInspectorFactory.getStandardPrimitiveObjectInspector instead.
+   */
+  protected StandardPrimitiveObjectInspector(Class<?> primitiveClass) {
+    this.primitiveClass = primitiveClass;
+  }
+
+  public Class<?> getPrimitiveClass() {
+    return primitiveClass;
+  }
+
+  public final Category getCategory() {
+    return Category.PRIMITIVE;
+  }
+
+  public String getTypeName() {
+    return primitiveClass.getName();
+  }
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardStructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardStructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardStructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StandardStructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,145 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * ListStructObjectInspector works on struct data that is stored as a Java List or Java Array object.
+ * Basically, the fields are stored sequentially in the List object.
+ * 
+ * The names of the struct fields and the internal structure of the struct fields are specified in 
+ * the ctor of the StructObjectInspector.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+public class StandardStructObjectInspector implements StructObjectInspector {
+
+  public static final Log LOG = LogFactory.getLog(StandardStructObjectInspector.class.getName());
+  
+  protected static class MyField implements StructField {
+    protected int fieldID;
+    protected String fieldName;
+    protected ObjectInspector fieldObjectInspector;
+    
+    public MyField(int fieldID, String fieldName, ObjectInspector fieldObjectInspector) {
+      this.fieldID = fieldID;
+      this.fieldName = fieldName.toLowerCase();
+      this.fieldObjectInspector = fieldObjectInspector;
+    }
+
+    public int getFieldID() {
+      return fieldID;
+    }
+    public String getFieldName() {
+      return fieldName;
+    }
+    public ObjectInspector getFieldObjectInspector() {
+      return fieldObjectInspector;
+    }
+    
+    public String toString() {
+      return "" + fieldID + ":" + fieldName;
+    }
+  }
+  
+  protected List<MyField> fields;
+  
+  public String getTypeName() {
+    return ObjectInspectorUtils.getStandardStructTypeName(this);
+  }
+  
+  /** Call ObjectInspectorFactory.getStandardListObjectInspector instead.
+   */
+  protected StandardStructObjectInspector(List<String> structFieldNames, List<ObjectInspector> structFieldObjectInspectors) {
+    init(structFieldNames, structFieldObjectInspectors);
+  }
+  protected void init(List<String> structFieldNames, List<ObjectInspector> structFieldObjectInspectors) {
+    assert(structFieldNames.size() == structFieldObjectInspectors.size());
+    
+    fields = new ArrayList<MyField>(structFieldNames.size()); 
+    for(int i=0; i<structFieldNames.size(); i++) {
+      fields.add(new MyField(i, structFieldNames.get(i), structFieldObjectInspectors.get(i)));
+    }
+  }
+  
+  protected StandardStructObjectInspector(List<StructField> fields) {
+    init(fields);
+  }
+  protected void init(List<StructField> fields) {
+    this.fields = new ArrayList<MyField>(fields.size()); 
+    for(int i=0; i<fields.size(); i++) {
+      this.fields.add(new MyField(i, fields.get(i).getFieldName(), fields.get(i).getFieldObjectInspector()));
+    }
+  }
+
+  
+  public final Category getCategory() {
+    return Category.STRUCT;
+  }
+
+  // Without Data
+  public StructField getStructFieldRef(String fieldName) {
+    return ObjectInspectorUtils.getStandardStructFieldRef(fieldName, fields);
+  }
+  public List<? extends StructField> getAllStructFieldRefs() {
+    return fields;
+  }
+
+  boolean warned = false;
+  // With Data
+  @SuppressWarnings("unchecked")
+  public Object getStructFieldData(Object data, StructField fieldRef) {
+    List<Object> list = getStructFieldsDataAsList(data);
+    if (list == null) {
+      return null;
+    }
+    MyField f = (MyField) fieldRef;
+    if (fields.size() != list.size() && !warned) {
+      // TODO: remove this
+      warned = true;
+      LOG.warn("Trying to access " + fields.size() + " fields inside a list of " + list.size()
+          + " elements: " + list);
+      LOG.warn("ignoring similar errors.");
+    }
+    int fieldID = f.getFieldID();
+    assert(fieldID >= 0 && fieldID < fields.size());
+    
+    return fieldID >= list.size() ? null : list.get(fieldID);
+  }
+  @SuppressWarnings("unchecked")
+  public List<Object> getStructFieldsDataAsList(Object data) {
+    if (data == null) {
+      return null;
+    }
+    if (data.getClass().isArray()) {
+      data = java.util.Arrays.asList((Object[])data);
+    }
+    List<Object> list = (List<Object>) data;
+    assert(list.size() == fields.size());
+    return list;
+  }
+
+  
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructField.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructField.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructField.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructField.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,39 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+/**
+ * StructField is an empty interface.
+ * 
+ * Classes implementing this interface are considered to represent 
+ * a field of a struct for this serde package.
+ */
+public interface StructField {
+
+  /**
+   * Get the name of the field.  The name should be always in lower-case.
+   */
+  String getFieldName();
+  
+  /**
+   * Get the ObjectInspector for the field.
+   */
+  ObjectInspector getFieldObjectInspector();
+  
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/StructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,42 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.List;
+
+
+public interface StructObjectInspector extends ObjectInspector {
+
+  // ** Methods that does not need a data object **
+  /** Returns all the fields. 
+   */
+  public List<? extends StructField> getAllStructFieldRefs();
+
+  /** Look up a field.
+   */
+  public StructField getStructFieldRef(String fieldName);
+
+  // ** Methods that need a data object **
+  /** returns null for data = null.
+   */
+  public Object getStructFieldData(Object data, StructField fieldRef);
+
+  /** returns null for data = null.
+   */
+  public List<Object> getStructFieldsDataAsList(Object data);
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftStructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftStructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftStructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftStructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,46 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+/**
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+class ThriftStructObjectInspector extends
+    ReflectionStructObjectInspector {
+
+  public boolean shouldIgnoreField(String name) {
+    return "__isset".equals(name);
+  }
+  
+  public boolean equals(Object b) {
+    if (this == b) return true;
+    if (!b.getClass().equals(this.getClass())) {
+      return false;
+    }
+    ThriftStructObjectInspector bInspector = (ThriftStructObjectInspector)b;
+    return objectClass.equals(bInspector.objectClass);
+  }
+
+  public int hashCode() {
+    return 7 * objectClass.hashCode(); 
+  }
+    
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/UnionStructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/UnionStructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/UnionStructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/UnionStructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,124 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * UnionStructObjectInspector unions several struct data into a single struct.
+ * Basically, the fields of these structs are put together sequentially into a single struct.
+ * 
+ * The object that can be acceptable by this ObjectInspector is a List of objects, each of
+ * which can be inspected by the ObjectInspector provided in the ctor of UnionStructObjectInspector.
+ * 
+ * Always use the ObjectInspectorFactory to create new ObjectInspector objects, instead
+ * of directly creating an instance of this class. 
+ */
+public class UnionStructObjectInspector implements StructObjectInspector {
+
+  public static class MyField implements StructField {
+    public int structID;
+    StructField structField;
+    public MyField(int structID, StructField structField) {
+      this.structID = structID;
+      this.structField = structField;
+    }
+    public String getFieldName() {
+      return structField.getFieldName();
+    }
+    public ObjectInspector getFieldObjectInspector() {
+      return structField.getFieldObjectInspector();
+    }
+  }
+  
+  List<StructObjectInspector> unionObjectInspectors;
+  List<MyField> fields;
+  
+  protected UnionStructObjectInspector(List<StructObjectInspector> unionObjectInspectors) {
+    init(unionObjectInspectors);
+  }
+
+  void init(List<StructObjectInspector> unionObjectInspectors) {
+    this.unionObjectInspectors = unionObjectInspectors;
+    
+    int totalSize = 0;
+    for (int i=0; i<unionObjectInspectors.size(); i++) {
+      totalSize += unionObjectInspectors.get(i).getAllStructFieldRefs().size();
+    }
+    
+    fields = new ArrayList<MyField>(totalSize); 
+    for (int i=0; i<unionObjectInspectors.size(); i++) {
+      StructObjectInspector oi = unionObjectInspectors.get(i);
+      for(StructField sf: oi.getAllStructFieldRefs()) {
+        fields.add(new MyField(i, sf));
+      }
+    }
+  }
+  
+  
+  public final Category getCategory() {
+    return Category.STRUCT;
+  }
+
+  public String getTypeName() {
+    return ObjectInspectorUtils.getStandardStructTypeName(this);
+  }
+
+  // Without Data
+  public StructField getStructFieldRef(String fieldName) {
+    return ObjectInspectorUtils.getStandardStructFieldRef(fieldName, fields);
+  }
+  public List<? extends StructField> getAllStructFieldRefs() {
+    return fields;
+  }
+
+  // With Data
+  @SuppressWarnings("unchecked")
+  public Object getStructFieldData(Object data, StructField fieldRef) {
+    if (data == null) {
+      return null;
+    }
+    if (data.getClass().isArray()) {
+      data = java.util.Arrays.asList((Object[])data);
+    }
+    MyField f = (MyField) fieldRef;
+    List<Object> list = (List<Object>) data;
+    assert(list.size() == unionObjectInspectors.size());
+    return unionObjectInspectors.get(f.structID).getStructFieldData(list.get(f.structID), f.structField);
+  }
+  @SuppressWarnings("unchecked")
+  public List<Object> getStructFieldsDataAsList(Object data) {
+    if (data == null) {
+      return null;
+    }
+    if (data.getClass().isArray()) {
+      data = java.util.Arrays.asList((Object[])data);
+    }
+    List<Object> list = (List<Object>) data;
+    assert(list.size() == unionObjectInspectors.size());
+    // Explode
+    ArrayList<Object> result = new ArrayList<Object>(fields.size());
+    for(int i=0; i<unionObjectInspectors.size(); i++) {
+      result.addAll(unionObjectInspectors.get(i).getStructFieldsDataAsList(list.get(i)));
+    }
+    return result;
+  }
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/MyStruct.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/MyStruct.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/MyStruct.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/MyStruct.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,35 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Class for testing TestReflectionObjectInspector.
+ */
+public class MyStruct {
+    public int myInt;
+    public Integer myInteger;
+    public String myString;
+    // Note: this is a recursive struct
+    public MyStruct myStruct;
+    public List<String> myListString;
+    public Map<String, String> myMapStringString;
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorUtils.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,101 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+import org.apache.hadoop.hive.serde2.thrift_test.Complex;
+import org.apache.hadoop.hive.serde2.thrift_test.IntString;
+
+import junit.framework.TestCase;
+
+public class TestObjectInspectorUtils extends TestCase {
+
+  public void testObjectInspectorUtils() throws Throwable {
+    try {
+      ObjectInspector oi1 = ObjectInspectorFactory.getReflectionObjectInspector(
+          Complex.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
+      
+      // metadata
+      assertEquals(Category.STRUCT, oi1.getCategory());
+      // standard ObjectInspector
+      StructObjectInspector soi = (StructObjectInspector)ObjectInspectorUtils.getStandardObjectInspector(oi1);
+      List<? extends StructField> fields = soi.getAllStructFieldRefs();
+      assertEquals(6, fields.size());
+      assertEquals(fields.get(0), soi.getStructFieldRef("aint"));
+  
+      // null
+      for (int i=0; i<fields.size(); i++) {
+        assertNull(soi.getStructFieldData(null, fields.get(i)));
+      }
+      
+      // real object
+      Complex cc = new Complex();
+      cc.aint = 1;
+      cc.astring = "test";
+      List<Integer> c2 = Arrays.asList(new Integer[]{1,2,3}); 
+      cc.lint =  c2;
+      List<String> c3 = Arrays.asList(new String[]{"one", "two"});
+      cc.lstring =  c3;
+      List<IntString> c4 = new ArrayList<IntString>(); 
+      cc.lintstring = c4;
+      cc.mstringstring = null; 
+      // standard object
+      Object c = ObjectInspectorUtils.getStandardObject(cc, oi1);
+      
+      assertEquals(1, soi.getStructFieldData(c, fields.get(0)));
+      assertEquals("test", soi.getStructFieldData(c, fields.get(1)));
+      assertEquals(c2, soi.getStructFieldData(c, fields.get(2)));
+      assertEquals(c3, soi.getStructFieldData(c, fields.get(3)));
+      assertEquals(c4, soi.getStructFieldData(c, fields.get(4)));
+      assertNull(soi.getStructFieldData(c, fields.get(5)));
+      ArrayList<Object> cfields = new ArrayList<Object>();
+      for(int i=0; i<6; i++) {
+        cfields.add(soi.getStructFieldData(c, fields.get(i)));
+      }
+      assertEquals(cfields, soi.getStructFieldsDataAsList(c));
+      
+      // sub fields
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class),
+          fields.get(0).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          fields.get(1).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class)),
+          fields.get(2).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(3).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getReflectionObjectInspector(IntString.class, 
+              ObjectInspectorFactory.ObjectInspectorOptions.THRIFT)),
+          fields.get(4).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardMapObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(5).getFieldObjectInspector());
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+    
+  }  
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestReflectionObjectInspectors.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestReflectionObjectInspectors.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestReflectionObjectInspectors.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestReflectionObjectInspectors.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,94 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+
+import junit.framework.TestCase;
+
+
+public class TestReflectionObjectInspectors extends TestCase {
+
+  public void testReflectionObjectInspectors() throws Throwable {
+    try {
+      ObjectInspector oi1 = ObjectInspectorFactory.getReflectionObjectInspector(
+          MyStruct.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
+      ObjectInspector oi2 = ObjectInspectorFactory.getReflectionObjectInspector(
+          MyStruct.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA);
+      assertEquals(oi1, oi2);
+      
+      // metadata
+      assertEquals(Category.STRUCT, oi1.getCategory());
+      StructObjectInspector soi = (StructObjectInspector)oi1;
+      List<? extends StructField> fields = soi.getAllStructFieldRefs(); 
+      assertEquals(6, fields.size());
+      assertEquals(fields.get(2), soi.getStructFieldRef("myString"));
+  
+      // null
+      for (int i=0; i<fields.size(); i++) {
+        assertNull(soi.getStructFieldData(null, fields.get(i)));
+      }
+      assertNull(soi.getStructFieldsDataAsList(null));
+      
+      // non nulls
+      MyStruct a = new MyStruct();
+      a.myInt = 1;
+      a.myInteger = 2;
+      a.myString = "test";
+      a.myStruct = a;
+      a.myListString = Arrays.asList(new String[]{"a", "b", "c"});
+      a.myMapStringString = new HashMap<String, String>();
+      a.myMapStringString.put("key", "value");
+      
+      assertEquals(1, soi.getStructFieldData(a, fields.get(0)));
+      assertEquals(2, soi.getStructFieldData(a, fields.get(1)));
+      assertEquals("test", soi.getStructFieldData(a, fields.get(2)));
+      assertEquals(a, soi.getStructFieldData(a, fields.get(3)));
+      assertEquals(a.myListString, soi.getStructFieldData(a, fields.get(4)));
+      assertEquals(a.myMapStringString, soi.getStructFieldData(a, fields.get(5)));
+      ArrayList<Object> afields = new ArrayList<Object>();
+      for(int i=0; i<6; i++) {
+        afields.add(soi.getStructFieldData(a, fields.get(i)));
+      }
+      assertEquals(afields, soi.getStructFieldsDataAsList(a));
+      
+      // sub fields
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class),
+          fields.get(0).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class),
+          fields.get(1).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          fields.get(2).getFieldObjectInspector());
+      assertEquals(soi, fields.get(3).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(4).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardMapObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(5).getFieldObjectInspector());
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestStandardObjectInspectors.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestStandardObjectInspectors.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestStandardObjectInspectors.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestStandardObjectInspectors.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,207 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+
+import junit.framework.TestCase;
+
+public class TestStandardObjectInspectors extends TestCase {
+
+  
+  void doTestStandardPrimitiveObjectInspector(Class<?> c) throws Throwable {
+    try {
+      StandardPrimitiveObjectInspector oi1 = ObjectInspectorFactory.getStandardPrimitiveObjectInspector(c);
+      StandardPrimitiveObjectInspector oi2 = ObjectInspectorFactory.getStandardPrimitiveObjectInspector(c);
+      assertEquals(oi1, oi2);
+      assertEquals(Category.PRIMITIVE, oi1.getCategory());
+      assertEquals(c, oi1.getPrimitiveClass());
+      assertEquals(c.getName(), oi1.getTypeName()); 
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  public void testStandardPrimitiveObjectInspector() throws Throwable {
+    try {
+      doTestStandardPrimitiveObjectInspector(Boolean.class);
+      doTestStandardPrimitiveObjectInspector(Byte.class);
+      doTestStandardPrimitiveObjectInspector(Integer.class);
+      doTestStandardPrimitiveObjectInspector(Long.class);
+      doTestStandardPrimitiveObjectInspector(Float.class);
+      doTestStandardPrimitiveObjectInspector(Double.class);
+      doTestStandardPrimitiveObjectInspector(String.class);
+      doTestStandardPrimitiveObjectInspector(java.sql.Date.class);
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+
+  public void testStandardListObjectInspector() throws Throwable {
+    try {
+      StandardListObjectInspector loi1 = ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class));
+      StandardListObjectInspector loi2 = ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class));
+      assertEquals(loi1, loi2);
+      
+      // metadata
+      assertEquals(Category.LIST, loi1.getCategory());
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class),
+          loi1.getListElementObjectInspector());
+      
+      // null
+      assertNull("loi1.getList(null) should be null.", loi1.getList(null));
+      assertEquals("loi1.getListLength(null) should be -1.", loi1.getListLength(null), -1);
+      assertNull("loi1.getListElement(null, 0) should be null", loi1.getListElement(null, 0));
+      assertNull("loi1.getListElement(null, 100) should be null", loi1.getListElement(null, 100));
+      
+      // ArrayList
+      ArrayList<Integer> list = new ArrayList<Integer>();
+      list.add(0);
+      list.add(1);
+      list.add(2);
+      list.add(3);
+      assertEquals(4, loi1.getList(list).size());
+      assertEquals(4, loi1.getListLength(list));
+      assertEquals(0, loi1.getListElement(list, 0));
+      assertEquals(3, loi1.getListElement(list, 3));
+      assertNull(loi1.getListElement(list, -1));
+      assertNull(loi1.getListElement(list, 4));
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+      
+  }
+
+  public void testStandardMapObjectInspector() throws Throwable {
+    try {
+      StandardMapObjectInspector moi1 = ObjectInspectorFactory.getStandardMapObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class)
+          );
+      StandardMapObjectInspector moi2 = ObjectInspectorFactory.getStandardMapObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class)
+          );
+      assertEquals(moi1, moi2);
+      
+      // metadata
+      assertEquals(Category.MAP, moi1.getCategory());
+      assertEquals(moi1.getMapKeyObjectInspector(), 
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
+      assertEquals(moi2.getMapValueObjectInspector(), 
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class));
+      
+      // null
+      assertNull(moi1.getMap(null));
+      assertNull(moi1.getMapValueElement(null, null));
+      assertNull(moi1.getMapValueElement(null, "nokey"));
+      assertEquals(-1, moi1.getMapSize(null));
+      assertEquals("map<" 
+          + ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class).getTypeName() + ","
+          + ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class).getTypeName() + ">",
+          moi1.getTypeName());
+  
+      // HashMap
+      HashMap<String, Integer> map = new HashMap<String, Integer>();
+      map.put("one", 1);
+      map.put("two", 2);
+      map.put("three", 3);
+      assertEquals(map, moi1.getMap(map));
+      assertEquals(3, moi1.getMapSize(map));
+      assertEquals(1, moi1.getMapValueElement(map, "one"));
+      assertEquals(2, moi1.getMapValueElement(map, "two"));
+      assertEquals(3, moi1.getMapValueElement(map, "three"));
+      assertNull(moi1.getMapValueElement(map, null));
+      assertNull(moi1.getMapValueElement(map, "null"));
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+      
+  }
+
+  
+  @SuppressWarnings("unchecked")
+  public void testStandardStructObjectInspector() throws Throwable {
+    try {
+      ArrayList<String> fieldNames = new ArrayList<String>();
+      fieldNames.add("firstInteger");
+      fieldNames.add("secondString");
+      fieldNames.add("thirdBoolean");
+      ArrayList<ObjectInspector> fieldObjectInspectors = new ArrayList<ObjectInspector>();
+      fieldObjectInspectors.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class));
+      fieldObjectInspectors.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
+      fieldObjectInspectors.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Boolean.class));
+      
+      StandardStructObjectInspector soi1 = ObjectInspectorFactory.getStandardStructObjectInspector(
+          fieldNames, fieldObjectInspectors);
+      StandardStructObjectInspector soi2 = ObjectInspectorFactory.getStandardStructObjectInspector(
+          (ArrayList<String>)fieldNames.clone(), (ArrayList<ObjectInspector>)fieldObjectInspectors.clone());
+      assertEquals(soi1, soi2);
+      
+      // metadata
+      assertEquals(Category.STRUCT, soi1.getCategory());
+      List<? extends StructField> fields = soi1.getAllStructFieldRefs();
+      assertEquals(3, fields.size());
+      for (int i=0; i<3; i++) {
+        assertEquals(fieldNames.get(i).toLowerCase(), fields.get(i).getFieldName());
+        assertEquals(fieldObjectInspectors.get(i), fields.get(i).getFieldObjectInspector());
+      }
+      assertEquals(fields.get(1), soi1.getStructFieldRef("secondString"));
+      StringBuilder structTypeName = new StringBuilder(); 
+      structTypeName.append("struct{");
+      for(int i=0; i<fields.size(); i++) {
+        if (i>0) structTypeName.append(",");
+        structTypeName.append(fields.get(i).getFieldName());
+        structTypeName.append(":");
+        structTypeName.append(fields.get(i).getFieldObjectInspector().getTypeName());
+      }
+      structTypeName.append("}");
+      assertEquals(structTypeName.toString(), soi1.getTypeName());
+  
+      // null
+      assertNull(soi1.getStructFieldData(null, fields.get(0)));
+      assertNull(soi1.getStructFieldData(null, fields.get(1)));
+      assertNull(soi1.getStructFieldData(null, fields.get(2)));
+      assertNull(soi1.getStructFieldsDataAsList(null));
+  
+      // HashStruct
+      ArrayList<Object> struct = new ArrayList<Object>(3);
+      struct.add(1);
+      struct.add("two");
+      struct.add(true);
+      
+      assertEquals(1, soi1.getStructFieldData(struct, fields.get(0)));
+      assertEquals("two", soi1.getStructFieldData(struct, fields.get(1)));
+      assertEquals(true, soi1.getStructFieldData(struct, fields.get(2)));
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+      
+  }
+  
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,101 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.hadoop.hive.serde2.thrift_test.Complex;
+import org.apache.hadoop.hive.serde2.thrift_test.IntString;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+
+public class TestThriftObjectInspectors extends TestCase {
+
+  public void testThriftObjectInspectors() throws Throwable {
+
+    try {
+      ObjectInspector oi1 = ObjectInspectorFactory.getReflectionObjectInspector(
+          Complex.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
+      ObjectInspector oi2 = ObjectInspectorFactory.getReflectionObjectInspector(
+          Complex.class, ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
+      assertEquals(oi1, oi2);
+      
+      // metadata
+      assertEquals(Category.STRUCT, oi1.getCategory());
+      StructObjectInspector soi = (StructObjectInspector)oi1; 
+      List<? extends StructField> fields = soi.getAllStructFieldRefs();
+      assertEquals(6, fields.size());
+      assertEquals(fields.get(0), soi.getStructFieldRef("aint"));
+  
+      // null
+      for (int i=0; i<fields.size(); i++) {
+        assertNull(soi.getStructFieldData(null, fields.get(i)));
+      }
+      
+      // real object
+      Complex c = new Complex();
+      c.aint = 1;
+      c.astring = "test";
+      List<Integer> c2 = Arrays.asList(new Integer[]{1,2,3}); 
+      c.lint =  c2;
+      List<String> c3 = Arrays.asList(new String[]{"one", "two"});
+      c.lstring =  c3;
+      List<IntString> c4 = new ArrayList<IntString>(); 
+      c.lintstring = c4;
+      c.mstringstring = null; 
+      
+      assertEquals(1, soi.getStructFieldData(c, fields.get(0)));
+      assertEquals("test", soi.getStructFieldData(c, fields.get(1)));
+      assertEquals(c2, soi.getStructFieldData(c, fields.get(2)));
+      assertEquals(c3, soi.getStructFieldData(c, fields.get(3)));
+      assertEquals(c4, soi.getStructFieldData(c, fields.get(4)));
+      assertNull(soi.getStructFieldData(c, fields.get(5)));
+      ArrayList<Object> cfields = new ArrayList<Object>();
+      for(int i=0; i<6; i++) {
+        cfields.add(soi.getStructFieldData(c, fields.get(i)));
+      }
+      assertEquals(cfields, soi.getStructFieldsDataAsList(c));
+      
+      // sub fields
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class),
+          fields.get(0).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          fields.get(1).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class)),
+          fields.get(2).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(3).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardListObjectInspector(
+          ObjectInspectorFactory.getReflectionObjectInspector(IntString.class, 
+              ObjectInspectorFactory.ObjectInspectorOptions.THRIFT)),
+          fields.get(4).getFieldObjectInspector());
+      assertEquals(ObjectInspectorFactory.getStandardMapObjectInspector(
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class),
+          ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class)),
+          fields.get(5).getFieldObjectInspector());
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestUnionStructObjectInspector.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestUnionStructObjectInspector.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestUnionStructObjectInspector.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestUnionStructObjectInspector.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,105 @@
+/**
+ * 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.hadoop.hive.serde2.objectinspector;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
+
+import junit.framework.TestCase;
+
+public class TestUnionStructObjectInspector extends TestCase {
+
+  
+  public void testUnionStructObjectInspector() throws Throwable {
+    try {
+      ArrayList<String> fieldNames1 = new ArrayList<String>();
+      fieldNames1.add("firstInteger");
+      fieldNames1.add("secondString");
+      fieldNames1.add("thirdBoolean");
+      ArrayList<ObjectInspector> fieldObjectInspectors1 = new ArrayList<ObjectInspector>();
+      fieldObjectInspectors1.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Integer.class));
+      fieldObjectInspectors1.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(String.class));
+      fieldObjectInspectors1.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Boolean.class));
+      StandardStructObjectInspector soi1 = ObjectInspectorFactory.getStandardStructObjectInspector(
+          fieldNames1, fieldObjectInspectors1);
+  
+      ArrayList<String> fieldNames2 = new ArrayList<String>();
+      fieldNames2.add("fourthDate");
+      fieldNames2.add("fifthLong");
+      ArrayList<ObjectInspector> fieldObjectInspectors2 = new ArrayList<ObjectInspector>();
+      fieldObjectInspectors2.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(java.sql.Date.class));
+      fieldObjectInspectors2.add(ObjectInspectorFactory.getStandardPrimitiveObjectInspector(Long.class));
+      StandardStructObjectInspector soi2 = ObjectInspectorFactory.getStandardStructObjectInspector(
+          fieldNames2, fieldObjectInspectors2);
+      
+      UnionStructObjectInspector usoi1 = ObjectInspectorFactory.getUnionStructObjectInspector(
+          Arrays.asList(new StructObjectInspector[]{soi1, soi2}));
+      UnionStructObjectInspector usoi2 = ObjectInspectorFactory.getUnionStructObjectInspector(
+          Arrays.asList(new StructObjectInspector[]{soi1, soi2}));
+  
+      assertEquals(usoi1, usoi2);
+      
+      // metadata
+      assertEquals(Category.STRUCT, usoi1.getCategory());
+      List<? extends StructField> fields = usoi1.getAllStructFieldRefs();
+      assertEquals(5, fields.size());
+      for (int i=0; i<5; i++) {
+        if (i<=2) {
+          assertEquals(fieldNames1.get(i).toLowerCase(), fields.get(i).getFieldName());
+          assertEquals(fieldObjectInspectors1.get(i), fields.get(i).getFieldObjectInspector());
+        } else {
+          assertEquals(fieldNames2.get(i-3).toLowerCase(), fields.get(i).getFieldName());
+          assertEquals(fieldObjectInspectors2.get(i-3), fields.get(i).getFieldObjectInspector());
+        }
+      }
+      assertEquals(fields.get(1), usoi1.getStructFieldRef("secondString"));
+      assertEquals(fields.get(4), usoi1.getStructFieldRef("fifthLong"));
+      
+      // null
+      for (int i=0; i<5; i++) {
+        assertNull(usoi1.getStructFieldData(null, fields.get(i)));
+      }
+      
+      // real struct
+      ArrayList<Object> struct1 = new ArrayList<Object>(3);
+      struct1.add(1);
+      struct1.add("two");
+      struct1.add(true);
+      ArrayList<Object> struct2 = new ArrayList<Object>(2);
+      struct2.add(java.sql.Date.valueOf("2008-08-08"));
+      struct2.add(new Long(111));
+      ArrayList<Object> struct = new ArrayList<Object>(2);
+      struct.add(struct1);
+      struct.add(struct2);
+      ArrayList<Object> all = new ArrayList<Object>(5);
+      all.addAll(struct1);
+      all.addAll(struct2);
+      
+      for (int i=0; i<5; i++) {
+        assertEquals(all.get(i), usoi1.getStructFieldData(struct, fields.get(i)));
+      }
+    } catch (Throwable e) {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Complex.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Complex.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Complex.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Complex.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,363 @@
+/**
+ * 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.
+ */
+
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package org.apache.hadoop.hive.serde2.thrift_test;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import com.facebook.thrift.*;
+
+import com.facebook.thrift.protocol.*;
+import com.facebook.thrift.transport.*;
+
+public class Complex implements TBase, java.io.Serializable {
+  public int aint;
+  public String astring;
+  public List<Integer> lint;
+  public List<String> lstring;
+  public List<IntString> lintstring;
+  public Map<String,String> mstringstring;
+
+  public final Isset __isset = new Isset();
+  public static final class Isset implements java.io.Serializable {
+    public boolean aint = false;
+    public boolean astring = false;
+    public boolean lint = false;
+    public boolean lstring = false;
+    public boolean lintstring = false;
+    public boolean mstringstring = false;
+  }
+
+  public Complex() {
+  }
+
+  public Complex(
+    int aint,
+    String astring,
+    List<Integer> lint,
+    List<String> lstring,
+    List<IntString> lintstring,
+    Map<String,String> mstringstring)
+  {
+    this();
+    this.aint = aint;
+    this.__isset.aint = true;
+    this.astring = astring;
+    this.__isset.astring = true;
+    this.lint = lint;
+    this.__isset.lint = true;
+    this.lstring = lstring;
+    this.__isset.lstring = true;
+    this.lintstring = lintstring;
+    this.__isset.lintstring = true;
+    this.mstringstring = mstringstring;
+    this.__isset.mstringstring = true;
+  }
+
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof Complex)
+      return this.equals((Complex)that);
+    return false;
+  }
+
+  public boolean equals(Complex that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_aint = true;
+    boolean that_present_aint = true;
+    if (this_present_aint || that_present_aint) {
+      if (!(this_present_aint && that_present_aint))
+        return false;
+      if (this.aint != that.aint)
+        return false;
+    }
+
+    boolean this_present_astring = true && (this.astring != null);
+    boolean that_present_astring = true && (that.astring != null);
+    if (this_present_astring || that_present_astring) {
+      if (!(this_present_astring && that_present_astring))
+        return false;
+      if (!this.astring.equals(that.astring))
+        return false;
+    }
+
+    boolean this_present_lint = true && (this.lint != null);
+    boolean that_present_lint = true && (that.lint != null);
+    if (this_present_lint || that_present_lint) {
+      if (!(this_present_lint && that_present_lint))
+        return false;
+      if (!this.lint.equals(that.lint))
+        return false;
+    }
+
+    boolean this_present_lstring = true && (this.lstring != null);
+    boolean that_present_lstring = true && (that.lstring != null);
+    if (this_present_lstring || that_present_lstring) {
+      if (!(this_present_lstring && that_present_lstring))
+        return false;
+      if (!this.lstring.equals(that.lstring))
+        return false;
+    }
+
+    boolean this_present_lintstring = true && (this.lintstring != null);
+    boolean that_present_lintstring = true && (that.lintstring != null);
+    if (this_present_lintstring || that_present_lintstring) {
+      if (!(this_present_lintstring && that_present_lintstring))
+        return false;
+      if (!this.lintstring.equals(that.lintstring))
+        return false;
+    }
+
+    boolean this_present_mstringstring = true && (this.mstringstring != null);
+    boolean that_present_mstringstring = true && (that.mstringstring != null);
+    if (this_present_mstringstring || that_present_mstringstring) {
+      if (!(this_present_mstringstring && that_present_mstringstring))
+        return false;
+      if (!this.mstringstring.equals(that.mstringstring))
+        return false;
+    }
+
+    return true;
+  }
+
+  public int hashCode() {
+    return 0;
+  }
+
+  public void read(TProtocol iprot) throws TException {
+    TField field;
+    iprot.readStructBegin();
+    while (true)
+    {
+      field = iprot.readFieldBegin();
+      if (field.type == TType.STOP) { 
+        break;
+      }
+      switch (field.id)
+      {
+        case 1:
+          if (field.type == TType.I32) {
+            this.aint = iprot.readI32();
+            this.__isset.aint = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 2:
+          if (field.type == TType.STRING) {
+            this.astring = iprot.readString();
+            this.__isset.astring = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 3:
+          if (field.type == TType.LIST) {
+            {
+              TList _list0 = iprot.readListBegin();
+              this.lint = new ArrayList<Integer>(_list0.size);
+              for (int _i1 = 0; _i1 < _list0.size; ++_i1)
+              {
+                int _elem2 = 0;
+                _elem2 = iprot.readI32();
+                this.lint.add(_elem2);
+              }
+              iprot.readListEnd();
+            }
+            this.__isset.lint = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 4:
+          if (field.type == TType.LIST) {
+            {
+              TList _list3 = iprot.readListBegin();
+              this.lstring = new ArrayList<String>(_list3.size);
+              for (int _i4 = 0; _i4 < _list3.size; ++_i4)
+              {
+                String _elem5 = null;
+                _elem5 = iprot.readString();
+                this.lstring.add(_elem5);
+              }
+              iprot.readListEnd();
+            }
+            this.__isset.lstring = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 5:
+          if (field.type == TType.LIST) {
+            {
+              TList _list6 = iprot.readListBegin();
+              this.lintstring = new ArrayList<IntString>(_list6.size);
+              for (int _i7 = 0; _i7 < _list6.size; ++_i7)
+              {
+                IntString _elem8 = new IntString();
+                _elem8 = new IntString();
+                _elem8.read(iprot);
+                this.lintstring.add(_elem8);
+              }
+              iprot.readListEnd();
+            }
+            this.__isset.lintstring = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 6:
+          if (field.type == TType.MAP) {
+            {
+              TMap _map9 = iprot.readMapBegin();
+              this.mstringstring = new HashMap<String,String>(2*_map9.size);
+              for (int _i10 = 0; _i10 < _map9.size; ++_i10)
+              {
+                String _key11;
+                String _val12;
+                _key11 = iprot.readString();
+                _val12 = iprot.readString();
+                this.mstringstring.put(_key11, _val12);
+              }
+              iprot.readMapEnd();
+            }
+            this.__isset.mstringstring = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        default:
+          TProtocolUtil.skip(iprot, field.type);
+          break;
+      }
+      iprot.readFieldEnd();
+    }
+    iprot.readStructEnd();
+  }
+
+  public void write(TProtocol oprot) throws TException {
+    TStruct struct = new TStruct("Complex");
+    oprot.writeStructBegin(struct);
+    TField field = new TField();
+    field.name = "aint";
+    field.type = TType.I32;
+    field.id = 1;
+    oprot.writeFieldBegin(field);
+    oprot.writeI32(this.aint);
+    oprot.writeFieldEnd();
+    if (this.astring != null) {
+      field.name = "astring";
+      field.type = TType.STRING;
+      field.id = 2;
+      oprot.writeFieldBegin(field);
+      oprot.writeString(this.astring);
+      oprot.writeFieldEnd();
+    }
+    if (this.lint != null) {
+      field.name = "lint";
+      field.type = TType.LIST;
+      field.id = 3;
+      oprot.writeFieldBegin(field);
+      {
+        oprot.writeListBegin(new TList(TType.I32, this.lint.size()));
+        for (int _iter13 : this.lint)        {
+          oprot.writeI32(_iter13);
+        }
+        oprot.writeListEnd();
+      }
+      oprot.writeFieldEnd();
+    }
+    if (this.lstring != null) {
+      field.name = "lstring";
+      field.type = TType.LIST;
+      field.id = 4;
+      oprot.writeFieldBegin(field);
+      {
+        oprot.writeListBegin(new TList(TType.STRING, this.lstring.size()));
+        for (String _iter14 : this.lstring)        {
+          oprot.writeString(_iter14);
+        }
+        oprot.writeListEnd();
+      }
+      oprot.writeFieldEnd();
+    }
+    if (this.lintstring != null) {
+      field.name = "lintstring";
+      field.type = TType.LIST;
+      field.id = 5;
+      oprot.writeFieldBegin(field);
+      {
+        oprot.writeListBegin(new TList(TType.STRUCT, this.lintstring.size()));
+        for (IntString _iter15 : this.lintstring)        {
+          _iter15.write(oprot);
+        }
+        oprot.writeListEnd();
+      }
+      oprot.writeFieldEnd();
+    }
+    if (this.mstringstring != null) {
+      field.name = "mstringstring";
+      field.type = TType.MAP;
+      field.id = 6;
+      oprot.writeFieldBegin(field);
+      {
+        oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING, this.mstringstring.size()));
+        for (String _iter16 : this.mstringstring.keySet())        {
+          oprot.writeString(_iter16);
+          oprot.writeString(this.mstringstring.get(_iter16));
+        }
+        oprot.writeMapEnd();
+      }
+      oprot.writeFieldEnd();
+    }
+    oprot.writeFieldStop();
+    oprot.writeStructEnd();
+  }
+
+  public String toString() {
+    StringBuilder sb = new StringBuilder("Complex(");
+    sb.append("aint:");
+    sb.append(this.aint);
+    sb.append(",astring:");
+    sb.append(this.astring);
+    sb.append(",lint:");
+    sb.append(this.lint);
+    sb.append(",lstring:");
+    sb.append(this.lstring);
+    sb.append(",lintstring:");
+    sb.append(this.lintstring);
+    sb.append(",mstringstring:");
+    sb.append(this.mstringstring);
+    sb.append(")");
+    return sb.toString();
+  }
+
+}
+

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Constants.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Constants.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Constants.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/Constants.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package org.apache.hadoop.hive.serde2.thrift_test;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import com.facebook.thrift.*;
+
+public class Constants {
+
+}

Added: hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/IntString.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/IntString.java?rev=696525&view=auto
==============================================================================
--- hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/IntString.java (added)
+++ hadoop/core/trunk/src/contrib/hive/serde/src/test/org/apache/hadoop/hive/serde2/thrift_test/IntString.java Wed Sep 17 17:09:17 2008
@@ -0,0 +1,167 @@
+/**
+ * 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.
+ */
+
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+package org.apache.hadoop.hive.serde2.thrift_test;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import com.facebook.thrift.*;
+
+import com.facebook.thrift.protocol.*;
+import com.facebook.thrift.transport.*;
+
+public class IntString implements TBase, java.io.Serializable {
+  public int myint;
+  public String mystring;
+
+  public final Isset __isset = new Isset();
+  public static final class Isset implements java.io.Serializable {
+    public boolean myint = false;
+    public boolean mystring = false;
+  }
+
+  public IntString() {
+  }
+
+  public IntString(
+    int myint,
+    String mystring)
+  {
+    this();
+    this.myint = myint;
+    this.__isset.myint = true;
+    this.mystring = mystring;
+    this.__isset.mystring = true;
+  }
+
+  public boolean equals(Object that) {
+    if (that == null)
+      return false;
+    if (that instanceof IntString)
+      return this.equals((IntString)that);
+    return false;
+  }
+
+  public boolean equals(IntString that) {
+    if (that == null)
+      return false;
+
+    boolean this_present_myint = true;
+    boolean that_present_myint = true;
+    if (this_present_myint || that_present_myint) {
+      if (!(this_present_myint && that_present_myint))
+        return false;
+      if (this.myint != that.myint)
+        return false;
+    }
+
+    boolean this_present_mystring = true && (this.mystring != null);
+    boolean that_present_mystring = true && (that.mystring != null);
+    if (this_present_mystring || that_present_mystring) {
+      if (!(this_present_mystring && that_present_mystring))
+        return false;
+      if (!this.mystring.equals(that.mystring))
+        return false;
+    }
+
+    return true;
+  }
+
+  public int hashCode() {
+    return 0;
+  }
+
+  public void read(TProtocol iprot) throws TException {
+    TField field;
+    iprot.readStructBegin();
+    while (true)
+    {
+      field = iprot.readFieldBegin();
+      if (field.type == TType.STOP) { 
+        break;
+      }
+      switch (field.id)
+      {
+        case 1:
+          if (field.type == TType.I32) {
+            this.myint = iprot.readI32();
+            this.__isset.myint = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        case 2:
+          if (field.type == TType.STRING) {
+            this.mystring = iprot.readString();
+            this.__isset.mystring = true;
+          } else { 
+            TProtocolUtil.skip(iprot, field.type);
+          }
+          break;
+        default:
+          TProtocolUtil.skip(iprot, field.type);
+          break;
+      }
+      iprot.readFieldEnd();
+    }
+    iprot.readStructEnd();
+  }
+
+  public void write(TProtocol oprot) throws TException {
+    TStruct struct = new TStruct("IntString");
+    oprot.writeStructBegin(struct);
+    TField field = new TField();
+    field.name = "myint";
+    field.type = TType.I32;
+    field.id = 1;
+    oprot.writeFieldBegin(field);
+    oprot.writeI32(this.myint);
+    oprot.writeFieldEnd();
+    if (this.mystring != null) {
+      field.name = "mystring";
+      field.type = TType.STRING;
+      field.id = 2;
+      oprot.writeFieldBegin(field);
+      oprot.writeString(this.mystring);
+      oprot.writeFieldEnd();
+    }
+    oprot.writeFieldStop();
+    oprot.writeStructEnd();
+  }
+
+  public String toString() {
+    StringBuilder sb = new StringBuilder("IntString(");
+    sb.append("myint:");
+    sb.append(this.myint);
+    sb.append(",mystring:");
+    sb.append(this.mystring);
+    sb.append(")");
+    return sb.toString();
+  }
+
+}
+



Mime
View raw message