/** * 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; import java.util.ArrayList; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils; import org.apache.hadoop.hive.serde2.objectinspector.StructField; import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; public class CustomNonSettableStructObjectInspector1 extends StructObjectInspector { public static final Logger LOG = LoggerFactory .getLogger(CustomNonSettableStructObjectInspector1.class.getName()); protected static class MyField implements StructField { protected int fieldID; protected String fieldName; protected ObjectInspector fieldObjectInspector; protected String fieldComment; protected MyField() { super(); } public MyField(int fieldID, String fieldName, ObjectInspector fieldObjectInspector) { this.fieldID = fieldID; this.fieldName = fieldName.toLowerCase(); this.fieldObjectInspector = fieldObjectInspector; } public MyField(int fieldID, String fieldName, ObjectInspector fieldObjectInspector, String fieldComment) { this(fieldID, fieldName, fieldObjectInspector); this.fieldComment = fieldComment; } public int getFieldID() { return fieldID; } public String getFieldName() { return fieldName; } public ObjectInspector getFieldObjectInspector() { return fieldObjectInspector; } public String getFieldComment() { return fieldComment; } @Override public String toString() { return "" + fieldID + ":" + fieldName; } } protected List<MyField> fields; protected CustomNonSettableStructObjectInspector1() { super(); } /** * Call ObjectInspectorFactory.getNonSettableStructObjectInspector instead. */ protected CustomNonSettableStructObjectInspector1(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), null)); } } public String getTypeName() { return ObjectInspectorUtils.getStandardStructTypeName(this); } public final Category getCategory() { return Category.STRUCT; } // Without Data @Override public StructField getStructFieldRef(String fieldName) { return ObjectInspectorUtils.getStandardStructFieldRef(fieldName, fields); } @Override public List<? extends StructField> getAllStructFieldRefs() { return fields; } // With Data - Unsupported for the test case @Override @SuppressWarnings("unchecked") public Object getStructFieldData(Object data, StructField fieldRef) { return null; } // Unsupported for the test case @Override @SuppressWarnings("unchecked") public List<Object> getStructFieldsDataAsList(Object data) { return null; } }