vvysotskyi commented on a change in pull request #2016: DRILL-7631: Updates to the Json Structure Parser URL: https://github.com/apache/drill/pull/2016#discussion_r390435908
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/parser/ValueDef.java ########## @@ -0,0 +1,84 @@ +/* + * 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.drill.exec.store.easy.json.parser; + +/** + * Description of a JSON value as inferred from looking ahead in + * the JSON stream. Includs a type (which can be empty for an empty + * array, or null), and an array size (which is 0 for simple values.) + * <p> + * To be clear, this is the JSON parser's best guess at a field type + * from the input token stream. This is <i>not</i> a description of the + * desired data type as JSON can only react to what it sees on input. + */ +public class ValueDef { + + /** + * Description of JSON types as derived from JSON tokens. + */ + public enum JsonType { + OBJECT, NULL, BOOLEAN, + INTEGER, FLOAT, STRING, EMBEDDED_OBJECT, + + /** + * Indicates an empty array. + */ + EMPTY, + + /** + * Indicates an unknown array, appears when replacing the + * value listener for an array. + */ + UNKNOWN; + + public boolean isObject() { return this == OBJECT; } + + public boolean isUnknown() { + return this == NULL || this == EMPTY || + this == UNKNOWN; + } + + public boolean isScalar() { + return !isObject() && !isUnknown(); + } + } + + public static final ValueDef UNKNOWN_ARRAY = new ValueDef(JsonType.UNKNOWN, 1); + public static final ValueDef UNKNOWN = new ValueDef(JsonType.UNKNOWN, 0); + + private final int arrayDims; + private final JsonType type; + + public ValueDef(JsonType type, int dims) { + this.type = type; + this.arrayDims = dims; + } + + public JsonType type() { return type; } + public int dimensions() { return arrayDims; } + public boolean isArray() { return arrayDims > 0; } + + @Override + public String toString() { + String result = type.name(); + for (int i = 0; i < arrayDims; i++) { + result += "[]"; Review comment: Could you please replace strings concatenation with `StringBuilder` usage. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
