ajantha-bhat commented on a change in pull request #3407: [CARBONDATA-3542] Support Map data type reading through Hive
URL: https://github.com/apache/carbondata/pull/3407#discussion_r336890663 ########## File path: integration/hive/src/main/java/org/apache/carbondata/hive/CarbonMapInspector.java ########## @@ -0,0 +1,186 @@ +/* + * 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.LinkedHashMap; +import java.util.Map; + +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.SettableMapObjectInspector; +import org.apache.hadoop.io.ArrayWritable; +import org.apache.hadoop.io.Writable; + +public class CarbonMapInspector implements SettableMapObjectInspector { + + protected final ObjectInspector keyInspector; + protected final ObjectInspector valueInspector; + + public CarbonMapInspector(final ObjectInspector keyInspector, + final ObjectInspector valueInspector) { + this.keyInspector = keyInspector; + this.valueInspector = valueInspector; + } + + @Override public String getTypeName() { + return "map<" + keyInspector.getTypeName() + "," + valueInspector.getTypeName() + ">"; + } + + @Override public Category getCategory() { + return Category.MAP; + } + + @Override + public ObjectInspector getMapKeyObjectInspector() { + return keyInspector; + } + + @Override + public ObjectInspector getMapValueObjectInspector() { + return valueInspector; + } + + @Override public Object getMapValueElement(Object data, Object key) { + if (data != null && key != null) { + Map<?, ?> map = (Map)data; + return map.get(key); + } else { + return null; + } + } + + @Override + public Map<?, ?> getMap(final Object data) { + if (data == null) { + return null; + } + + if (data instanceof ArrayWritable) { + final Writable[] mapArray = ((ArrayWritable) data).get(); + if (mapArray == null) { + return null; + } + + final Map<Writable, Writable> map = new LinkedHashMap<>(); + for (final Writable obj : mapArray) { + final ArrayWritable mapObj = (ArrayWritable) obj; + final Writable[] arr = mapObj.get(); + for (int i = 0; i < arr.length; i++) { + map.put(((ArrayWritable) arr[i]).get()[0], ((ArrayWritable) arr[i]).get()[1]); + } + } + Review comment: remove empty lines here and other places in the newly modified code. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |