[ https://issues.apache.org/jira/browse/HIVE-21240?focusedWorklogId=230306&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-230306 ]
ASF GitHub Bot logged work on HIVE-21240: ----------------------------------------- Author: ASF GitHub Bot Created on: 19/Apr/19 22:59 Start Date: 19/Apr/19 22:59 Worklog Time Spent: 10m Work Description: b-slim commented on pull request #530: HIVE-21240: JSON SerDe Deserialize Re-Write URL: https://github.com/apache/hive/pull/530#discussion_r277108764 ########## File path: serde/src/java/org/apache/hadoop/hive/serde2/json/HiveJsonReader.java ########## @@ -0,0 +1,532 @@ +/* + * 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.json; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.hadoop.hive.common.type.Date; +import org.apache.hadoop.hive.common.type.HiveChar; +import org.apache.hadoop.hive.common.type.HiveDecimal; +import org.apache.hadoop.hive.common.type.HiveVarchar; +import org.apache.hadoop.hive.common.type.Timestamp; +import org.apache.hadoop.hive.common.type.TimestampTZ; +import org.apache.hadoop.hive.serde2.SerDeException; +import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.StructField; +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory; +import org.apache.hadoop.hive.serde2.typeinfo.BaseCharTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo; +import org.apache.hadoop.hive.serde2.typeinfo.TimestampLocalTZTypeInfo; +import org.apache.hive.common.util.TimestampParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeType; +import com.fasterxml.jackson.databind.node.TextNode; +import com.google.common.base.Preconditions; + +/** + * This class converts JSON strings into Java or Hive Primitive objects. + * + * Support types are:<br/> + * <br/> + * <table border="1"> + * <tr> + * <th>JSON Type</th> + * <th>Java Type</th> + * <th>Notes</th> + * </tr> + * <tr> + * <td>Object</td> + * <td>java.util.List</td> + * <td>Each element may be different type + * </tr> + * <tr> + * <td>Array</td> + * <td>java.util.List</td> + * <td>Each element is same type</td> + * </tr> + * <tr> + * <td>Map</td> + * <td>java.util.Map</td> + * <td>Keys must be same primitive type; every value is the same type</td> + * </tr> + * </table> + */ +public class HiveJsonReader { + + private static final Logger LOG = + LoggerFactory.getLogger(HiveJsonReader.class); + + private final Map<Pair<StructObjectInspector, String>, StructField> discoveredFields = + new HashMap<>(); + + private final Set<Pair<StructObjectInspector, String>> discoveredUnknownFields = + new HashSet<>(); + + private final EnumSet<Feature> features = EnumSet.noneOf(Feature.class); + + private final ObjectMapper objectMapper; + + private final TimestampParser tsParser; + private BinaryEncoding binaryEncoding; + private final ObjectInspector oi; + + /** + * Enumeration that defines all on/off features for this reader. + */ + public enum Feature { + COL_INDEX_PARSING, PRIMITIVE_TO_WRITABLE, IGNORE_UKNOWN_FIELDS Review comment: can you please document those features? ---------------------------------------------------------------- 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 230306) Time Spent: 1h 10m (was: 1h) > JSON SerDe Re-Write > ------------------- > > Key: HIVE-21240 > URL: https://issues.apache.org/jira/browse/HIVE-21240 > Project: Hive > Issue Type: Improvement > Components: Serializers/Deserializers > Affects Versions: 4.0.0, 3.1.1 > Reporter: David Mollitor > Assignee: David Mollitor > Priority: Major > Labels: pull-request-available > Fix For: 4.0.0 > > Attachments: HIVE-21240.1.patch, HIVE-21240.1.patch, > HIVE-21240.10.patch, HIVE-21240.11.patch, HIVE-21240.11.patch, > HIVE-21240.11.patch, HIVE-21240.11.patch, HIVE-21240.2.patch, > HIVE-21240.3.patch, HIVE-21240.4.patch, HIVE-21240.5.patch, > HIVE-21240.6.patch, HIVE-21240.7.patch, HIVE-21240.9.patch, > HIVE-24240.8.patch, kafka_storage_handler.diff > > Time Spent: 1h 10m > Remaining Estimate: 0h > > The JSON SerDe has a few issues, I will link them to this JIRA. > * Use Jackson Tree parser instead of manually parsing > * Added support for base-64 encoded data (the expected format when using JSON) > * Added support to skip blank lines (returns all columns as null values) > * Current JSON parser accepts, but does not apply, custom timestamp formats > in most cases > * Added some unit tests > * Added cache for column-name to column-index searches, currently O\(n\) for > each row processed, for each column in the row -- This message was sent by Atlassian JIRA (v7.6.3#76005)