public class HoodieAvroUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static org.apache.avro.Schema |
METADATA_FIELD_SCHEMA |
static org.apache.avro.Schema |
RECORD_KEY_SCHEMA |
| Constructor and Description |
|---|
HoodieAvroUtils() |
| Modifier and Type | Method and Description |
|---|---|
static org.apache.avro.generic.GenericRecord |
addCommitMetadataToRecord(org.apache.avro.generic.GenericRecord record,
String instantTime,
String commitSeqno)
Adds the Hoodie commit metadata into the provided Generic Record.
|
static org.apache.avro.generic.GenericRecord |
addHoodieKeyToRecord(org.apache.avro.generic.GenericRecord record,
String recordKey,
String partitionPath,
String fileName) |
static String |
addMetadataColumnTypes(String hiveColumnTypes) |
static org.apache.avro.Schema |
addMetadataFields(org.apache.avro.Schema schema)
Adds the Hoodie metadata fields to the given schema.
|
static org.apache.avro.Schema |
appendNullSchemaFields(org.apache.avro.Schema schema,
List<String> newFieldNames)
Add null fields to passed in schema.
|
static byte[] |
avroToBytes(org.apache.avro.generic.GenericRecord record)
Convert a given avro record to bytes.
|
static byte[] |
avroToJson(org.apache.avro.generic.GenericRecord record,
boolean pretty)
Convert a given avro record to json and return the encoded bytes.
|
static org.apache.avro.generic.GenericRecord |
bytesToAvro(byte[] bytes,
org.apache.avro.Schema schema)
Convert serialized bytes back into avro record.
|
static org.apache.avro.generic.GenericRecord |
bytesToAvro(byte[] bytes,
org.apache.avro.Schema writerSchema,
org.apache.avro.Schema readerSchema)
Convert serialized bytes back into avro record.
|
static byte[] |
compress(String text) |
static Object |
convertValueForSpecificDataTypes(org.apache.avro.Schema fieldSchema,
Object fieldValue)
This method converts values for fields with certain Avro/Parquet data types that require special handling.
|
static org.apache.avro.Schema |
createHoodieWriteSchema(org.apache.avro.Schema originalSchema) |
static org.apache.avro.Schema |
createHoodieWriteSchema(String originalSchema) |
static String |
decompress(byte[] bytes) |
static org.apache.avro.Schema |
generateProjectionSchema(org.apache.avro.Schema originalSchema,
List<String> fieldNames)
Generate a reader schema off the provided writeSchema, to just project out the provided columns.
|
static Object |
getNestedFieldVal(org.apache.avro.generic.GenericRecord record,
String fieldName,
boolean returnNullIfNotFound)
Obtain value of the provided field, denoted by dot notation.
|
static String |
getNestedFieldValAsString(org.apache.avro.generic.GenericRecord record,
String fieldName,
boolean returnNullIfNotFound)
Obtain value of the provided field as string, denoted by dot notation.
|
static org.apache.avro.Schema |
getNullSchema() |
static org.apache.avro.Schema |
getRecordKeyPartitionPathSchema()
Fetch schema for record key and partition path.
|
static org.apache.avro.Schema |
getRecordKeySchema() |
static <T extends org.apache.avro.generic.IndexedRecord> |
indexedRecordToBytes(T record) |
static boolean |
isMetadataField(String fieldName) |
static org.apache.avro.generic.GenericRecord |
jsonBytesToAvro(byte[] bytes,
org.apache.avro.Schema schema)
Convert json bytes back into avro record.
|
static org.apache.avro.Schema |
removeMetadataFields(org.apache.avro.Schema schema) |
static org.apache.avro.generic.GenericRecord |
rewriteRecord(org.apache.avro.generic.GenericRecord oldRecord,
org.apache.avro.Schema newSchema)
Given a avro record with a given schema, rewrites it into the new schema while setting fields only from the new
schema.
|
static String |
sanitizeName(String name)
Sanitizes Name according to Avro rule for names.
|
static org.apache.avro.generic.GenericRecord |
stitchRecords(org.apache.avro.generic.GenericRecord left,
org.apache.avro.generic.GenericRecord right,
org.apache.avro.Schema stitchedSchema) |
public static final org.apache.avro.Schema METADATA_FIELD_SCHEMA
public static final org.apache.avro.Schema RECORD_KEY_SCHEMA
public static byte[] avroToBytes(org.apache.avro.generic.GenericRecord record)
public static <T extends org.apache.avro.generic.IndexedRecord> byte[] indexedRecordToBytes(T record)
public static byte[] avroToJson(org.apache.avro.generic.GenericRecord record,
boolean pretty)
throws IOException
record - The GenericRecord to convertpretty - Whether to pretty-print the json outputIOExceptionpublic static org.apache.avro.generic.GenericRecord bytesToAvro(byte[] bytes,
org.apache.avro.Schema schema)
throws IOException
IOExceptionpublic static org.apache.avro.generic.GenericRecord bytesToAvro(byte[] bytes,
org.apache.avro.Schema writerSchema,
org.apache.avro.Schema readerSchema)
throws IOException
IOExceptionpublic static org.apache.avro.generic.GenericRecord jsonBytesToAvro(byte[] bytes,
org.apache.avro.Schema schema)
throws IOException
IOExceptionpublic static boolean isMetadataField(String fieldName)
public static org.apache.avro.Schema createHoodieWriteSchema(org.apache.avro.Schema originalSchema)
public static org.apache.avro.Schema createHoodieWriteSchema(String originalSchema)
public static org.apache.avro.Schema addMetadataFields(org.apache.avro.Schema schema)
public static org.apache.avro.Schema removeMetadataFields(org.apache.avro.Schema schema)
public static org.apache.avro.Schema getRecordKeySchema()
public static org.apache.avro.Schema getRecordKeyPartitionPathSchema()
public static org.apache.avro.generic.GenericRecord addHoodieKeyToRecord(org.apache.avro.generic.GenericRecord record,
String recordKey,
String partitionPath,
String fileName)
public static org.apache.avro.Schema appendNullSchemaFields(org.apache.avro.Schema schema,
List<String> newFieldNames)
schema - Passed in schemanewFieldNames - Null Field names to be addedpublic static org.apache.avro.generic.GenericRecord addCommitMetadataToRecord(org.apache.avro.generic.GenericRecord record,
String instantTime,
String commitSeqno)
public static org.apache.avro.generic.GenericRecord stitchRecords(org.apache.avro.generic.GenericRecord left,
org.apache.avro.generic.GenericRecord right,
org.apache.avro.Schema stitchedSchema)
public static org.apache.avro.generic.GenericRecord rewriteRecord(org.apache.avro.generic.GenericRecord oldRecord,
org.apache.avro.Schema newSchema)
public static byte[] compress(String text)
public static String decompress(byte[] bytes)
public static org.apache.avro.Schema generateProjectionSchema(org.apache.avro.Schema originalSchema,
List<String> fieldNames)
public static String getNestedFieldValAsString(org.apache.avro.generic.GenericRecord record, String fieldName, boolean returnNullIfNotFound)
public static Object getNestedFieldVal(org.apache.avro.generic.GenericRecord record, String fieldName, boolean returnNullIfNotFound)
public static Object convertValueForSpecificDataTypes(org.apache.avro.Schema fieldSchema, Object fieldValue)
fieldSchema - avro field schemafieldValue - avro field valuepublic static org.apache.avro.Schema getNullSchema()
Copyright © 2021 The Apache Software Foundation. All rights reserved.