Package org.apache.pinot.spi.utils
Class JsonUtils
- java.lang.Object
-
- org.apache.pinot.spi.utils.JsonUtils
-
public class JsonUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringARRAY_INDEX_KEYstatic StringARRAY_PATHstatic com.fasterxml.jackson.databind.ObjectWriterDEFAULT_PRETTY_WRITERstatic com.fasterxml.jackson.databind.ObjectReaderDEFAULT_READERstatic com.fasterxml.jackson.databind.ObjectWriterDEFAULT_WRITERstatic StringKEY_SEPARATORstatic com.fasterxml.jackson.core.type.TypeReference<HashMap<String,Object>>MAP_TYPE_REFERENCEstatic intMAX_COMBINATIONSstatic com.fasterxml.jackson.databind.ObjectReaderREADER_WITH_BIG_DECIMALstatic StringVALUE_KEYstatic StringWILDCARD
-
Method Summary
Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonNodebytesToJsonNode(byte[] jsonBytes)static <T> TbytesToObject(byte[] jsonBytes, Class<T> valueType)static ObjectextractValue(com.fasterxml.jackson.databind.JsonNode jsonValue, FieldSpec fieldSpec)static com.fasterxml.jackson.databind.JsonNodefileToFirstJsonNode(File jsonFile)Reads the first json object from the file that can contain multiple objectsstatic com.fasterxml.jackson.databind.JsonNodefileToJsonNode(File jsonFile)static <T> List<T>fileToList(File jsonFile, Class<T> valueType)static <T> TfileToObject(File jsonFile, Class<T> valueType)static List<Map<String,String>>flatten(com.fasterxml.jackson.databind.JsonNode node, JsonIndexConfig jsonIndexConfig)Flattens the given json node.static SchemagetPinotSchemaFromJsonFile(File jsonFile, Map<String,FieldSpec.FieldType> fieldTypeMap, TimeUnit timeUnit, List<String> fieldsToUnnest, String delimiter, ComplexTypeConfig.CollectionNotUnnestedToJson collectionNotUnnestedToJson)static SchemagetPinotSchemaFromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Map<String,FieldSpec.FieldType> fieldTypeMap, TimeUnit timeUnit, List<String> fieldsToUnnest, String delimiter, ComplexTypeConfig.CollectionNotUnnestedToJson collectionNotUnnestedToJson)static com.fasterxml.jackson.databind.JsonNodeinputStreamToJsonNode(InputStream jsonInputStream)static <T> TinputStreamToObject(InputStream jsonInputStream, Class<T> valueType)static <T> org.apache.commons.lang3.tuple.Pair<T,Map<String,Object>>inputStreamToObjectAndUnrecognizedProperties(InputStream jsonInputStream, Class<T> valueType)static Map<String,Object>jsonNodeToMap(com.fasterxml.jackson.databind.JsonNode jsonNode)static <T> TjsonNodeToObject(com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)static <T> TjsonNodeToObject(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> valueType)static com.fasterxml.jackson.databind.node.ArrayNodenewArrayNode()static com.fasterxml.jackson.databind.node.ObjectNodenewObjectNode()static byte[]objectToBytes(Object object)static com.fasterxml.jackson.databind.JsonNodeobjectToJsonNode(Object object)static StringobjectToPrettyString(Object object)static StringobjectToString(Object object)static com.fasterxml.jackson.databind.JsonNodestringToJsonNode(String jsonString)static com.fasterxml.jackson.databind.JsonNodestringToJsonNodeWithBigDecimal(String jsonString)static <T> TstringToObject(String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)static <T> TstringToObject(String jsonString, Class<T> valueType)static <T> org.apache.commons.lang3.tuple.Pair<T,Map<String,Object>>stringToObjectAndUnrecognizedProperties(String jsonString, Class<T> valueType)static FieldSpec.DataTypevalueOf(com.fasterxml.jackson.databind.JsonNode jsonNode)Returns the data type stored in Pinot that is associated with the given Avro type.
-
-
-
Field Detail
-
VALUE_KEY
public static final String VALUE_KEY
- See Also:
- Constant Field Values
-
KEY_SEPARATOR
public static final String KEY_SEPARATOR
- See Also:
- Constant Field Values
-
ARRAY_PATH
public static final String ARRAY_PATH
- See Also:
- Constant Field Values
-
ARRAY_INDEX_KEY
public static final String ARRAY_INDEX_KEY
- See Also:
- Constant Field Values
-
MAX_COMBINATIONS
public static final int MAX_COMBINATIONS
- See Also:
- Constant Field Values
-
WILDCARD
public static final String WILDCARD
- See Also:
- Constant Field Values
-
DEFAULT_READER
public static final com.fasterxml.jackson.databind.ObjectReader DEFAULT_READER
-
DEFAULT_WRITER
public static final com.fasterxml.jackson.databind.ObjectWriter DEFAULT_WRITER
-
DEFAULT_PRETTY_WRITER
public static final com.fasterxml.jackson.databind.ObjectWriter DEFAULT_PRETTY_WRITER
-
READER_WITH_BIG_DECIMAL
public static final com.fasterxml.jackson.databind.ObjectReader READER_WITH_BIG_DECIMAL
-
-
Method Detail
-
stringToObject
public static <T> T stringToObject(String jsonString, Class<T> valueType) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
inputStreamToObjectAndUnrecognizedProperties
public static <T> org.apache.commons.lang3.tuple.Pair<T,Map<String,Object>> inputStreamToObjectAndUnrecognizedProperties(InputStream jsonInputStream, Class<T> valueType) throws IOException
- Throws:
IOException
-
stringToObjectAndUnrecognizedProperties
public static <T> org.apache.commons.lang3.tuple.Pair<T,Map<String,Object>> stringToObjectAndUnrecognizedProperties(String jsonString, Class<T> valueType) throws IOException
- Throws:
IOException
-
stringToObject
public static <T> T stringToObject(String jsonString, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws IOException
- Throws:
IOException
-
stringToJsonNode
public static com.fasterxml.jackson.databind.JsonNode stringToJsonNode(String jsonString) throws IOException
- Throws:
IOException
-
stringToJsonNodeWithBigDecimal
public static com.fasterxml.jackson.databind.JsonNode stringToJsonNodeWithBigDecimal(String jsonString) throws IOException
- Throws:
IOException
-
fileToObject
public static <T> T fileToObject(File jsonFile, Class<T> valueType) throws IOException
- Throws:
IOException
-
fileToList
public static <T> List<T> fileToList(File jsonFile, Class<T> valueType) throws IOException
- Throws:
IOException
-
fileToJsonNode
public static com.fasterxml.jackson.databind.JsonNode fileToJsonNode(File jsonFile) throws IOException
- Throws:
IOException
-
fileToFirstJsonNode
@Nullable public static com.fasterxml.jackson.databind.JsonNode fileToFirstJsonNode(File jsonFile) throws IOException
Reads the first json object from the file that can contain multiple objects- Throws:
IOException
-
inputStreamToObject
public static <T> T inputStreamToObject(InputStream jsonInputStream, Class<T> valueType) throws IOException
- Throws:
IOException
-
inputStreamToJsonNode
public static com.fasterxml.jackson.databind.JsonNode inputStreamToJsonNode(InputStream jsonInputStream) throws IOException
- Throws:
IOException
-
bytesToObject
public static <T> T bytesToObject(byte[] jsonBytes, Class<T> valueType) throws IOException- Throws:
IOException
-
bytesToJsonNode
public static com.fasterxml.jackson.databind.JsonNode bytesToJsonNode(byte[] jsonBytes) throws IOException- Throws:
IOException
-
jsonNodeToObject
public static <T> T jsonNodeToObject(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> valueType) throws IOException- Throws:
IOException
-
jsonNodeToObject
public static <T> T jsonNodeToObject(com.fasterxml.jackson.databind.JsonNode jsonNode, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws IOException- Throws:
IOException
-
jsonNodeToMap
public static Map<String,Object> jsonNodeToMap(com.fasterxml.jackson.databind.JsonNode jsonNode) throws IOException
- Throws:
IOException
-
objectToString
public static String objectToString(Object object) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
objectToPrettyString
public static String objectToPrettyString(Object object) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
objectToBytes
public static byte[] objectToBytes(Object object) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
objectToJsonNode
public static com.fasterxml.jackson.databind.JsonNode objectToJsonNode(Object object)
-
newObjectNode
public static com.fasterxml.jackson.databind.node.ObjectNode newObjectNode()
-
newArrayNode
public static com.fasterxml.jackson.databind.node.ArrayNode newArrayNode()
-
extractValue
public static Object extractValue(@Nullable com.fasterxml.jackson.databind.JsonNode jsonValue, FieldSpec fieldSpec)
-
flatten
public static List<Map<String,String>> flatten(com.fasterxml.jackson.databind.JsonNode node, JsonIndexConfig jsonIndexConfig)
Flattens the given json node.Json array will be flattened into multiple records, where each record has a special key to store the index of the element.
E.g. { "name": "adam", "addresses": [ { "country": "us", "street": "main st", "number": 1 }, { "country": "ca", "street": "second st", "number": 2 } ] } --> [ { ".name": "adam", ".addresses.$index": "0", ".addresses..country": "us", ".addresses..street": "main st", ".addresses..number": "1" }, { ".name": "adam", ".addresses.$index": "1", ".addresses..country": "ca", ".addresses..street": "second st", ".addresses..number": "2" } ]
-
getPinotSchemaFromJsonFile
public static Schema getPinotSchemaFromJsonFile(File jsonFile, @Nullable Map<String,FieldSpec.FieldType> fieldTypeMap, @Nullable TimeUnit timeUnit, @Nullable List<String> fieldsToUnnest, String delimiter, ComplexTypeConfig.CollectionNotUnnestedToJson collectionNotUnnestedToJson) throws IOException
- Throws:
IOException
-
getPinotSchemaFromJsonNode
public static Schema getPinotSchemaFromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, @Nullable Map<String,FieldSpec.FieldType> fieldTypeMap, @Nullable TimeUnit timeUnit, List<String> fieldsToUnnest, String delimiter, ComplexTypeConfig.CollectionNotUnnestedToJson collectionNotUnnestedToJson)
-
valueOf
public static FieldSpec.DataType valueOf(com.fasterxml.jackson.databind.JsonNode jsonNode)
Returns the data type stored in Pinot that is associated with the given Avro type.
-
-