code stringlengths 23 201k | docstring stringlengths 17 96.2k | func_name stringlengths 0 235 | language stringclasses 1
value | repo stringlengths 8 72 | path stringlengths 11 317 | url stringlengths 57 377 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
static Schema convertHiveSchemaToAvro(@Nonnull final Table table) {
Preconditions.checkNotNull(table);
String recordName = table.getTableName();
String recordNamespace = table.getDbName() + "." + recordName;
final List<FieldSchema> cols = new ArrayList<>(table.getSd().getCols());
if (isPartitioned... | This method return avro schema including partition columns for table
If avro schema exists in table properties, retrieve it from table properties
Otherwise, avro schema is converted from hive schema
@param table
@param strictMode if set to true, we do not fall back to Hive schema
@return Avro schema for table includi... | convertHiveSchemaToAvro | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema getCasePreservedSchemaFromTblProperties(@Nonnull final Table table) {
Preconditions.checkNotNull(table);
// First try avro.schema.literal
String schemaStr = readSchemaFromSchemaLiteral(table);
Schema schema = null;
// Then, try dali.row.schema
if (Strings.isNullOrEmpty(schemaStr)... | Returns case sensitive schema from table properties or null if not present
Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return Avro schema stored under 'avro.schema.literal', under 'dali.row.schema',
or null if none of the above are present | getCasePreservedSchemaFromTblProperties | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
public static Object defaultValue(Schema.Field field) {
if (AvroCompatibilityHelper.fieldHasDefault(field)) {
return AvroCompatibilityHelper.getGenericDefaultValue(field);
}
return null;
} | Returns case sensitive schema from table properties or null if not present
Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return Avro schema stored under 'avro.schema.literal', under 'dali.row.schema',
or null if none of the above are present | defaultValue | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static void appendField(@Nonnull Schema.Field field, @Nonnull SchemaBuilder.FieldAssembler<Schema> fieldAssembler) {
Preconditions.checkNotNull(field);
Preconditions.checkNotNull(fieldAssembler);
Object defaultValue = defaultValue(field);
SchemaBuilder.GenericDefault genericDefault =
fieldAsse... | Returns case sensitive schema from table properties or null if not present
Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return Avro schema stored under 'avro.schema.literal', under 'dali.row.schema',
or null if none of the above are present | appendField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static void appendField(@Nonnull String fieldName, @Nonnull RelDataType fieldRelDataType, @Nullable String doc,
@Nonnull SchemaBuilder.FieldAssembler<Schema> fieldAssembler, boolean isNullable) {
Preconditions.checkNotNull(fieldName);
Preconditions.checkNotNull(fieldRelDataType);
Preconditions.checkNo... | This method appends a field to avro schema SchemaBuilder.FieldAssembler<Schema>
@param fieldName
@param fieldRelDataType
@param doc
@param fieldAssembler | appendField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static boolean isFieldNullable(@Nonnull RexCall rexCall, @Nonnull Schema inputSchema) {
Preconditions.checkNotNull(rexCall);
Preconditions.checkNotNull(inputSchema);
// we first filter against these static list of functions, whose nullability should be
// determined by calcite rather than avro.schema.l... | This method appends a field to avro schema SchemaBuilder.FieldAssembler<Schema>
@param fieldName
@param fieldRelDataType
@param doc
@param fieldAssembler | isFieldNullable | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static void appendField(@Nonnull String fieldName, @Nonnull Schema.Field field,
@Nonnull SchemaBuilder.FieldAssembler<Schema> fieldAssembler) {
Preconditions.checkNotNull(fieldName);
Preconditions.checkNotNull(field);
Preconditions.checkNotNull(fieldAssembler);
Object defaultValue = defaultValue(... | This method appends a field to avro schema SchemaBuilder.FieldAssembler<Schema>
@param fieldName
@param fieldRelDataType
@param doc
@param fieldAssembler | appendField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String getFieldName(String oldName, String suggestedNewName) {
Preconditions.checkNotNull(oldName);
Preconditions.checkNotNull(suggestedNewName);
String newName = suggestedNewName;
if (suggestedNewName.equals(oldName.toLowerCase())) {
// we do not allow renaming the field to all lower-casi... | This method appends a field to avro schema SchemaBuilder.FieldAssembler<Schema>
@param fieldName
@param fieldRelDataType
@param doc
@param fieldAssembler | getFieldName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static String getLiteralValueAsString(@Nonnull RexLiteral rexLiteral) {
StringWriter documentationWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(documentationWriter);
rexLiteral.printAsJava(printWriter);
printWriter.flush();
return documentationWriter.toString();
... | This method appends a field to avro schema SchemaBuilder.FieldAssembler<Schema>
@param fieldName
@param fieldRelDataType
@param doc
@param fieldAssembler | getLiteralValueAsString | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static boolean isColumn(int fieldIndex, @Nonnull RelNode inputRelNode) {
return !(inputRelNode instanceof LogicalAggregate)
|| fieldIndex < ((LogicalAggregate) inputRelNode).getGroupSet().cardinality();
} | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | isColumn | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String generateDocumentationForLiteral(@Nonnull RexLiteral rexLiteral) {
return "Field created from view literal with value: " + getLiteralValueAsString(rexLiteral);
} | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | generateDocumentationForLiteral | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String generateDocumentationForAggregate(@Nonnull AggregateCall aggregateCall) {
return "Field created in view by applying aggregate function of type: " + aggregateCall.getAggregation().getKind();
} | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | generateDocumentationForAggregate | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String generateDocumentationForFunctionCall(@Nonnull RexCall rexCall, @Nonnull Schema inputSchema,
@Nonnull RelNode inputRelNode) {
StringJoiner args = new StringJoiner(", ");
for (RexNode rexNode : rexCall.getOperands()) {
SqlKind nodeKind = rexNode.getKind();
switch (nodeKind) {
... | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | generateDocumentationForFunctionCall | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String toAvroQualifiedName(@Nonnull String name) {
Preconditions.checkNotNull(name);
return name.replace("$", "_");
} | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | toAvroQualifiedName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static boolean isPartitioned(@Nonnull Table tableOrView) {
Preconditions.checkNotNull(tableOrView);
List<FieldSchema> partitionColumns = getPartitionCols(tableOrView);
return (partitionColumns.size() != 0);
} | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | isPartitioned | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static List<Schema.Field> cloneFieldList(List<Schema.Field> fieldList, boolean isPartCol) {
List<Schema.Field> result = new ArrayList<>();
for (Schema.Field field : fieldList) {
String fieldDoc = isPartCol ? "This is the partition column. "
+ "Partition columns, if present in the schema,... | Given an input {@link RelNode} and the index of a field in the {@link RelNode}'s corresponding Avro schema,
determine if the field with the specified index is a column from a table.
@param fieldIndex the index of a field in the <code>inputRelNode</code>'s corresponding Avro schema
@param inputRelNode the input {@link R... | cloneFieldList | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@VisibleForTesting
static List<Schema.Field> cloneFieldList(List<Schema.Field> fieldList) {
return cloneFieldList(fieldList, false);
} | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | cloneFieldList | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static void replicateFieldProps(Schema.Field srcField, Schema.Field targetField) {
final List<String> existingPropNames = AvroCompatibilityHelper.getAllPropNames(targetField);
for (String propName : AvroCompatibilityHelper.getAllPropNames(srcField)) {
if (existingPropNames.contains(propName)) {
co... | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | replicateFieldProps | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static void replicateSchemaProps(Schema srcSchema, Schema targetSchema) {
final List<String> existingPropNames = AvroCompatibilityHelper.getAllPropNames(targetSchema);
for (String propName : AvroCompatibilityHelper.getAllPropNames(srcSchema)) {
if (existingPropNames.contains(propName)) {
continue;... | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | replicateSchemaProps | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema addPartitionColsToSchema(@Nonnull Schema schema, @Nonnull Table tableOrView) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(tableOrView);
if (!isPartitioned(tableOrView)) {
return schema;
}
Schema partitionColumnsSchema =
convertFieldSchemaToAvroSchema... | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | addPartitionColsToSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema setupNameAndNamespace(@Nonnull Schema schema, @Nonnull String schemaName,
@Nonnull String schemaNamespace) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(schemaName);
Preconditions.checkNotNull(schemaNamespace);
// setup name
Schema schemaWithProperName = setup... | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | setupNameAndNamespace | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema joinSchemas(@Nonnull Schema leftSchema, @Nonnull Schema rightSchema) {
Preconditions.checkNotNull(leftSchema);
Preconditions.checkNotNull(rightSchema);
List<Schema.Field> combinedSchemaFields = cloneFieldList(leftSchema.getFields());
combinedSchemaFields.addAll(cloneFieldList(rightSchema.... | Exposed method for cloning fieldList as `isPartCol=false` is an internal case. | joinSchemas | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema mergeUnionRecordSchema(@Nonnull Schema originalLeftSchema, @Nonnull Schema originalRightSchema,
boolean strictMode, boolean forceLowercase) {
Preconditions.checkNotNull(originalLeftSchema);
Preconditions.checkNotNull(originalRightSchema);
Schema leftSchema = originalLeftSchema;
Sche... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | mergeUnionRecordSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema extractIfOption(Schema schema) {
if (isNullableType(schema)) {
return getOtherTypeFromNullableType(schema);
} else {
return schema;
}
} | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | extractIfOption | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static Schema getUnionFieldSchema(@Nonnull Schema leftSchema, @Nonnull Schema rightSchema,
boolean strictMode) {
Preconditions.checkNotNull(leftSchema);
Preconditions.checkNotNull(rightSchema);
Schema.Type leftSchemaType = leftSchema.getType();
Schema.Type rightSchemaType = rightSchema.ge... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | getUnionFieldSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema makeNonNullable(Schema schema) {
if (isNullableType(schema)) {
return getOtherTypeFromNullableType(schema);
} else {
return schema;
}
} | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | makeNonNullable | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema makeNullable(Schema schema, boolean nullAsSecond) {
if (schema.getType() == NULL || isNullableType(schema)) {
return schema;
} else if (schema.getType() == UNION) {
for (Schema innerSchema : schema.getTypes()) {
if (innerSchema.getType() == NULL) {
return schema;
... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | makeNullable | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static boolean isNullSecond(Schema schema) {
return schema != null && isNullableType(schema) && schema.getTypes().get(1).getType().equals(Schema.Type.NULL);
} | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | isNullSecond | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema discardNullFromUnionIfExist(Schema schema) {
Preconditions.checkArgument(schema.getType() == Schema.Type.UNION, "Expected union schema but was passed: %s",
schema);
List<Schema> result = new ArrayList<>();
for (Schema nested : schema.getTypes()) {
if (!(nested.getType() == Schema... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | discardNullFromUnionIfExist | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static boolean nullExistInUnion(Schema schema) {
Preconditions.checkArgument(schema.getType() == Schema.Type.UNION, "Expected union schema but was passed: %s",
schema);
for (Schema nested : schema.getTypes()) {
if (nested.getType() == Schema.Type.NULL) {
return true;
}
}
retu... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | nullExistInUnion | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static boolean isSameNamespace(@Nonnull Schema leftSchema, @Nonnull Schema rightSchema, boolean strictMode) {
return !strictMode || Objects.equals(leftSchema.getNamespace(), rightSchema.getNamespace());
} | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | isSameNamespace | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static void appendFieldWithNewNamespace(@Nonnull Schema.Field field, @Nonnull String namespace,
@Nonnull SchemaBuilder.FieldAssembler<Schema> fieldAssembler) {
Preconditions.checkNotNull(field);
Preconditions.checkNotNull(namespace);
Preconditions.checkNotNull(fieldAssembler);
Schema fiel... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | appendFieldWithNewNamespace | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static Schema setupNestedNamespaceForRecord(@Nonnull Schema schema, @Nonnull String namespace) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(namespace);
if (!schema.getType().equals(Schema.Type.RECORD)) {
throw new IllegalArgumentException(
"Input schemas must be ... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | setupNestedNamespaceForRecord | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static Schema setupNestedNamespace(@Nonnull Schema schema, @Nonnull String namespace) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(namespace);
switch (schema.getType()) {
case NULL:
case BOOLEAN:
case BYTES:
case DOUBLE:
case FLOAT:
case INT:
... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | setupNestedNamespace | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema modifySchemaBeforeMerge(@Nonnull Schema originalSchema) {
Schema modifiedSchema = originalSchema;
if (originalSchema.getNamespace() == null) {
modifiedSchema = Schema.createRecord(originalSchema.getName(), originalSchema.getDoc(), originalSchema.getName(),
originalSchema.isError()... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | modifySchemaBeforeMerge | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static Schema setupTopLevelRecordName(@Nonnull Schema schema, @Nonnull String schemaName) {
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(schemaName);
Schema avroSchema = Schema.createRecord(schemaName, schema.getDoc(), schema.getNamespace(), schema.isError());
List<Schema.Fie... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | setupTopLevelRecordName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static Schema convertFieldSchemaToAvroSchema(@Nonnull final String recordName,
@Nonnull final String recordNamespace, final boolean mkFieldsOptional, @Nonnull final List<FieldSchema> columns) {
Preconditions.checkNotNull(recordName);
Preconditions.checkNotNull(recordNamespace);
Preconditions.c... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | convertFieldSchemaToAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static List<FieldSchema> getPartitionCols(@Nonnull Table tableOrView) {
Preconditions.checkNotNull(tableOrView);
List<FieldSchema> partKeys = tableOrView.getPartitionKeys();
if (partKeys == null) {
partKeys = new ArrayList<>();
tableOrView.setPartitionKeys(partKeys);
}
return p... | This method merges two input schemas of LogicalUnion operator, or throws exception if they can't be merged.
@param originalLeftSchema Left schema to be merged
@param originalRightSchema Right schema to be merged
@param strictMode If set to true, namespaces are required to be same.
If set to false, we... | getPartitionCols | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static String readSchemaFromSchemaLiteral(@Nonnull Table table) {
Preconditions.checkNotNull(table);
String schemaStr = table.getParameters().get(AvroSerdeUtils.AVRO_SCHEMA_LITERAL);
if (Strings.isNullOrEmpty(schemaStr)) {
schemaStr = table.getSd().getSerdeInfo().getParameters().get(AvroSerde... | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | readSchemaFromSchemaLiteral | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static String getCompleteName(@Nonnull Table table) {
Preconditions.checkNotNull(table);
return table.getDbName() + "@" + table.getTableName();
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | getCompleteName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static String getStandardName(@Nonnull String name) {
Preconditions.checkNotNull(name);
String[] sArr = name.split("_");
StringBuilder sb = new StringBuilder();
for (String str : sArr) {
sb.append(StringUtils.capitalize(str));
}
return sb.toString();
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | getStandardName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
protected static boolean visit(Schema schema) {
return AvroSchemaVisitor.visit(schema, new HasDuplicateLowercaseColumnNames());
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | visit | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@Override
public Boolean record(Schema record, List<String> names, List<Boolean> fieldResults) {
return fieldResults.stream().anyMatch(x -> x) || names.stream()
.collect(Collectors.groupingBy(String::toLowerCase)).values().stream().anyMatch(x -> x.size() > 1);
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | record | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@Override
public Boolean union(Schema union, List<Boolean> optionResults) {
return optionResults.stream().anyMatch(x -> x);
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | union | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@Override
public Boolean array(Schema array, Boolean elementResult) {
return elementResult;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | array | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@Override
public Boolean map(Schema map, Boolean valueResult) {
return valueResult;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | map | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
@Override
public Boolean primitive(Schema primitive) {
return false;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | primitive | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema copyRecord(Schema record, List<Schema.Field> newFields) {
Schema copy;
copy = Schema.createRecord(record.getName(), record.getDoc(), record.getNamespace(), record.isError());
copy.setFields(cloneFieldList(newFields));
replicateSchemaProps(record, copy);
return copy;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | copyRecord | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema.Field copyField(Schema.Field field, Schema newSchema) {
Schema.Field copy = AvroCompatibilityHelper.createSchemaField(field.name(), newSchema, field.doc(),
defaultValue(field), field.order());
replicateFieldProps(field, copy);
return copy;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | copyField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String makeCompatibleName(String name) {
if (!validAvroName(name)) {
return sanitize(name);
}
return name;
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | makeCompatibleName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static boolean validAvroName(String name) {
int length = name.length();
Preconditions.checkArgument(length > 0, "Empty name");
char first = name.charAt(0);
if (!(Character.isLetter(first) || first == '_')) {
return false;
}
for (int i = 1; i < length; i++) {
char character = name.ch... | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | validAvroName | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static String sanitize(String name) {
int length = name.length();
StringBuilder sb = new StringBuilder(name.length());
char first = name.charAt(0);
if (!(Character.isLetter(first) || first == '_')) {
sb.append(sanitize(first));
} else {
sb.append(first);
}
for (int i = 1; i < le... | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | sanitize | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
private static String sanitize(char character) {
if (Character.isDigit(character)) {
return "_" + character;
}
return "_x" + Integer.toHexString(character).toUpperCase();
} | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | sanitize | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static StructTypeInfo structTypeInfoFromCols(List<FieldSchema> cols) {
Preconditions.checkArgument(cols != null && cols.size() > 0, "No Hive schema present");
List<String> fieldNames = cols.stream().map(FieldSchema::getName).collect(Collectors.toList());
List<TypeInfo> fieldTypeInfos =
cols.stream()... | Note: This method is modified based on SchemaUtilities in Dali codebase
@param table
@return | structTypeInfoFromCols | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
static Schema reorderOptionIfRequired(Schema schema, Object defaultValue) {
if (isNullableType(schema) && defaultValue != null && schema.getTypes().get(0).getType() == Schema.Type.NULL) {
return Schema.createUnion(Arrays.asList(schema.getTypes().get(1), schema.getTypes().get(0)));
} else {
return sc... | Reorders an option schema so that the type of the provided default value is the first type in the option schema
e.g. If the schema is [null, int] and the default value is 1, the returned schema is [int, null]
If the schema is not an option schema or if there is no default value, schema is returned as-is | reorderOptionIfRequired | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/SchemaUtilities.java | BSD-2-Clause |
public static Schema visit(Schema schema) {
return AvroSchemaVisitor.visit(schema, new ToLowercaseSchemaVisitor());
} | Lowercase field names for Avro schema | visit | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema record(Schema record, List<String> names, List<Schema> fields) {
Schema lowercasedSchema =
Schema.createRecord(record.getName().toLowerCase(), record.getDoc(), record.getNamespace(), record.isError());
List<Schema.Field> lowercasedFields = Lists.newArrayListWithExpectedSize(fi... | Lowercase field names for Avro schema | record | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema union(Schema union, List<Schema> options) {
List<Schema> unionOptions = Lists.newArrayListWithExpectedSize(options.size());
for (Schema option : options) {
unionOptions.add(option);
}
return Schema.createUnion(unionOptions);
} | Lowercase field names for Avro schema | union | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema array(Schema array, Schema element) {
return Schema.createArray(element);
} | Lowercase field names for Avro schema | array | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema map(Schema map, Schema value) {
return Schema.createMap(value);
} | Lowercase field names for Avro schema | map | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema primitive(Schema primitive) {
return primitive;
} | Lowercase field names for Avro schema | primitive | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
private Schema.Field lowercaseField(Schema.Field field, Schema schema) {
Schema.Field lowercasedField = AvroCompatibilityHelper.createSchemaField(field.name().toLowerCase(), schema,
field.doc(), SchemaUtilities.defaultValue(field), field.order());
SchemaUtilities.replicateFieldProps(field, lowercasedFi... | Lowercase field names for Avro schema | lowercaseField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToLowercaseSchemaVisitor.java | BSD-2-Clause |
public static Schema visit(Schema schema) {
return SchemaUtilities.makeNonNullable(AvroSchemaVisitor.visit(schema, new ToNullableSchemaVisitor()));
} | Converts all the fields (including nested fields) to be nullable for a given schema | visit | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema record(Schema record, List<String> names, List<Schema> fields) {
Schema nullableSchema =
Schema.createRecord(record.getName(), record.getDoc(), record.getNamespace(), record.isError());
List<Schema.Field> nullableFields = Lists.newArrayListWithExpectedSize(fields.size());
... | Converts all the fields (including nested fields) to be nullable for a given schema | record | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema union(Schema union, List<Schema> options) {
List<Schema> unionOptions = new ArrayList<>(options);
return Schema.createUnion(unionOptions);
} | Converts all the fields (including nested fields) to be nullable for a given schema | union | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema array(Schema array, Schema element) {
return Schema.createArray(SchemaUtilities.makeNullable(element, false));
} | Converts all the fields (including nested fields) to be nullable for a given schema | array | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema map(Schema map, Schema value) {
return Schema.createMap(SchemaUtilities.makeNullable(value, false));
} | Converts all the fields (including nested fields) to be nullable for a given schema | map | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
@Override
public Schema primitive(Schema primitive) {
return primitive;
} | Converts all the fields (including nested fields) to be nullable for a given schema | primitive | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
private Schema.Field nullableField(Schema.Field field, Schema schema) {
final Object defaultValue = SchemaUtilities.defaultValue(field);
// While calling `makeNullable` method, if the default value is not null, we need to put null as the second option
// i.e. schema = int, defaultValue = 1, the resultant sc... | Converts all the fields (including nested fields) to be nullable for a given schema | nullableField | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ToNullableSchemaVisitor.java | BSD-2-Clause |
Schema convertFieldsTypeInfoToAvroSchema(String recordNamespace, String recordName, List<String> fieldNames,
List<TypeInfo> fieldTypeInfos) {
final List<Schema.Field> fields = new ArrayList<>();
for (int i = 0; i < fieldNames.size(); ++i) {
final TypeInfo fieldTypeInfo = fieldTypeInfos.get(i);
... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | convertFieldsTypeInfoToAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
Schema convertTypeInfoToAvroSchema(TypeInfo typeInfo, String recordNamespace, String recordName) {
Schema schema;
ObjectInspector.Category c = typeInfo.getCategory();
switch (c) {
case STRUCT:
// We don't cache the structType because otherwise it could be possible that a field
// "las... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | convertTypeInfoToAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private Schema parseSchemaFromUnion(UnionTypeInfo typeInfo, final String recordNamespace, final String recordName) {
List<TypeInfo> typeInfos = typeInfo.getAllUnionObjectTypeInfos();
// A union might contain duplicate struct typeinfos because the underlying Avro union has two Record types with
// different... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | parseSchemaFromUnion | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private Schema parseSchemaFromStruct(final StructTypeInfo typeInfo, final String recordNamespace,
final String recordName) {
final Schema recordSchema = convertFieldsTypeInfoToAvroSchema(recordNamespace, recordName,
typeInfo.getAllStructFieldNames(), typeInfo.getAllStructFieldTypeInfos());
return... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | parseSchemaFromStruct | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private Schema parseSchemaFromList(final ListTypeInfo typeInfo, final String recordNamespace,
final String recordName) {
Schema listSchema = convertTypeInfoToAvroSchema(typeInfo.getListElementTypeInfo(), recordNamespace, recordName);
return Schema.createArray(listSchema);
} | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | parseSchemaFromList | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private Schema parseSchemaFromMap(final MapTypeInfo typeInfo, final String recordNamespace, final String recordName) {
final TypeInfo keyTypeInfo = typeInfo.getMapKeyTypeInfo();
final PrimitiveObjectInspector.PrimitiveCategory pc = ((PrimitiveTypeInfo) keyTypeInfo).getPrimitiveCategory();
if (pc != Primitiv... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | parseSchemaFromMap | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private Schema parseSchemaFromPrimitive(PrimitiveTypeInfo primitiveTypeInfo) {
Schema schema;
switch (primitiveTypeInfo.getPrimitiveCategory()) {
case LONG:
schema = Schema.create(Schema.Type.LONG);
break;
case DATE:
schema = Schema.create(Schema.Type.INT);
schema.ad... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | parseSchemaFromPrimitive | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private static Schema wrapInNullableUnion(Schema schema) {
Schema wrappedSchema = schema;
switch (schema.getType()) {
case NULL:
break;
case UNION:
List<Schema> unionSchemas = Lists.newArrayList(Schema.create(Schema.Type.NULL));
unionSchemas.addAll(schema.getTypes());
... | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | wrapInNullableUnion | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
private static String removePrefix(String name) {
final int idx = name.lastIndexOf('.');
if (idx > 0) {
return name.substring(idx + 1);
}
return name;
} | This class converts Hive TypeInfo schema to avro schema
The main API is convertFieldsTypeInfoToAvroSchema | removePrefix | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/TypeInfoToAvroSchemaConverter.java | BSD-2-Clause |
public static ViewToAvroSchemaConverter create(HiveMetastoreClient hiveMetastoreClient) {
return new ViewToAvroSchemaConverter(hiveMetastoreClient);
} | Use this method to create a new instance of ViewToAvroSchemaConverter
@param hiveMetastoreClient {@link HiveMetastoreClient} object
@return an instance of ViewToAvroSchemaConverter | create | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
public Schema toAvroSchema(String dbName, String tableOrViewName, boolean strictMode) {
Preconditions.checkNotNull(dbName);
Preconditions.checkNotNull(tableOrViewName);
Schema avroSchema = inferAvroSchema(dbName, tableOrViewName, strictMode, false);
return avroSchema;
} | An API to generate the avro schema for a view
@param dbName database name
@param tableOrViewName table or view name
@param strictMode if strictMode is set to True, we will not fall back to Hive schema if avro.schema.literal
is missing in table properties. In addition, original namespace in base ... | toAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
public Schema toAvroSchema(String dbName, String tableOrViewName, boolean strictMode, boolean forceLowercase) {
Preconditions.checkNotNull(dbName);
Preconditions.checkNotNull(tableOrViewName);
Schema avroSchema = inferAvroSchema(dbName, tableOrViewName, strictMode, forceLowercase);
return avroSchema;
... | An API to generate the avro schema for a view
@param dbName database name
@param tableOrViewName table or view name
@param strictMode if strictMode is set to True, we will not fall back to Hive schema if avro.schema.literal
is missing in table properties. In addition, original namespace in base ... | toAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
public Schema toAvroSchema(String dbName, String tableOrViewName) {
Preconditions.checkNotNull(dbName);
Preconditions.checkNotNull(tableOrViewName);
Schema avroSchema = inferAvroSchema(dbName, tableOrViewName, false, false);
return avroSchema;
} | An API to generate the avro schema for a view
@param dbName database name
@param tableOrViewName table or view name
@return avro schema for a given Dali view [dbName, viewName] | toAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
@VisibleForTesting
public Schema toAvroSchema(String sql) {
Preconditions.checkNotNull(sql);
RelNode relNode = hiveToRelConverter.convertSql(sql);
return relToAvroSchemaConverter.convert(relNode, false, false);
} | An API to generate the avro schema for a SQL string
@param sql SQL string literal
@return avro schema for a given sql query | toAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
@VisibleForTesting
public Schema toAvroSchema(String sql, boolean strictMode, boolean forceLowercase) {
Preconditions.checkNotNull(sql);
RelNode relNode = hiveToRelConverter.convertSql(sql);
return relToAvroSchemaConverter.convert(relNode, strictMode, forceLowercase);
} | An API to generate the avro schema for a SQL string
@param sql SQL string literal
@return avro schema for a given sql query | toAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
public String toAvroSchemaString(String dbName, String tableOrViewName, boolean strictMode, boolean isPrettyPrint) {
return toAvroSchema(dbName, tableOrViewName, strictMode).toString(isPrettyPrint);
} | An API to generate the avro schema string for a view
@param dbName database name
@param tableOrViewName table or view name
@param strictMode if strictMode is set to True, we will not fall back to Hive schema if avro.schema.literal
is missing in table properties. In addition, original namespace i... | toAvroSchemaString | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
public String toAvroSchemaString(String dbName, String tableOrViewName, boolean strictMode) {
return toAvroSchemaString(dbName, tableOrViewName, strictMode, false);
} | An API to generate the avro schema string for a view
@param dbName database name
@param tableOrViewName table or view name
@param strictMode if strictMode is set to True, we will not fall back to Hive schema if avro.schema.literal
is missing in table properties. In addition, original namespace i... | toAvroSchemaString | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
private Schema inferAvroSchema(String dbName, String tableOrViewName, boolean strictMode, boolean forceLowercase) {
Preconditions.checkNotNull(dbName);
Preconditions.checkNotNull(tableOrViewName);
Table tableOrView = hiveMetastoreClient.getTable(dbName, tableOrViewName);
if (tableOrView == null) {
... | An API to generate the avro schema string for a view
@param dbName database name
@param tableOrViewName table or view name
@param strictMode if strictMode is set to True, we will not fall back to Hive schema if avro.schema.literal
is missing in table properties. In addition, original namespace i... | inferAvroSchema | java | linkedin/coral | coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/main/java/com/linkedin/coral/schema/avro/ViewToAvroSchemaConverter.java | BSD-2-Clause |
@Override
public void close() throws HiveException {
forwardObj[0] = count;
forward(forwardObj);
forward(forwardObj);
} | CoralTestUDTF outputs the number of rows seen, twice. It's output twice
to test outputting of rows on close with lateral view. | close | java | linkedin/coral | coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | BSD-2-Clause |
@Override
public StructObjectInspector initialize(StructObjectInspector argOIs) {
ArrayList<String> fieldNames = new ArrayList<>();
ArrayList<ObjectInspector> fieldOIs = new ArrayList<>();
fieldNames.add("col1");
fieldOIs.add(PrimitiveObjectInspectorFactory.javaIntObjectInspector);
return ObjectIn... | CoralTestUDTF outputs the number of rows seen, twice. It's output twice
to test outputting of rows on close with lateral view. | initialize | java | linkedin/coral | coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | BSD-2-Clause |
@Override
public void process(Object[] args) {
count++;
} | CoralTestUDTF outputs the number of rows seen, twice. It's output twice
to test outputting of rows on close with lateral view. | process | java | linkedin/coral | coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | https://github.com/linkedin/coral/blob/master/coral-schema/src/test/java/com/linkedin/coral/hive/hive2rel/CoralTestUDTF.java | BSD-2-Clause |
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// runs after the Spring context has been initialized
try {
initHiveMetastoreClient(hivePropsLocation);
} catch (Exception e) {
e.printStackTrace();
}
} | Class defining the REST endpoints to translate queries using Coral. | onApplicationEvent | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | BSD-2-Clause |
@PostMapping("/api/translations/translate")
public ResponseEntity translate(@RequestBody TranslateRequestBody translateRequestBody) {
final String sourceLanguage = translateRequestBody.getSourceLanguage();
final String targetLanguage = translateRequestBody.getTargetLanguage();
final String query = transla... | Class defining the REST endpoints to translate queries using Coral. | translate | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | BSD-2-Clause |
@PostMapping("/api/incremental/rewrite")
public ResponseEntity getIncrementalInfo(@RequestBody IncrementalRequestBody incrementalRequestBody)
throws JSONException {
final String query = incrementalRequestBody.getQuery();
final List<String> tableNames = incrementalRequestBody.getTableNames();
final S... | Class defining the REST endpoints to translate queries using Coral. | getIncrementalInfo | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationController.java | BSD-2-Clause |
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// runs after the Spring context has been initialized
try {
CoralProvider.initLocalMetastore();
} catch (Exception e) {
e.printStackTrace();
}
} | Additional REST endpoints for interacting with the local metastore. | onApplicationEvent | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | BSD-2-Clause |
@PostMapping("/api/catalog-ops/execute")
public ResponseEntity createInLocalMetastore(@RequestBody String statement) {
String[] splitQuery = statement.split("\\s+");
if (!isCreateQuery(splitQuery)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("Only queries starting with \"CREAT... | Additional REST endpoints for interacting with the local metastore. | createInLocalMetastore | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | BSD-2-Clause |
private boolean isCreateQuery(String[] splitQuery) {
if (splitQuery.length < 3) {
return false;
}
return splitQuery[0].equalsIgnoreCase("create") && (splitQuery[1].equalsIgnoreCase("table")
|| splitQuery[1].equalsIgnoreCase("database") || splitQuery[1].equalsIgnoreCase("view"));
} | Method to check that query starts with "CREATE DATABASE|TABLE|VIEW" | isCreateQuery | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/controller/TranslationControllerLocal.java | BSD-2-Clause |
public static HiveMetastoreClient getMetastoreClient(String hivePropsLocation) throws Exception {
InputStream hivePropsStream = null;
if (hivePropsLocation.trim().isEmpty()) {
hivePropsStream = CoralProvider.class.getClassLoader().getResourceAsStream("hive.properties");
} else {
hivePropsStream ... | Utility class to get Hive metastore client for local hive or remote based hive using kerberos | getMetastoreClient | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/metastore/MetastoreProvider.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/metastore/MetastoreProvider.java | BSD-2-Clause |
private static IMetaStoreClient getRemoteMetastoreClient(Properties props)
throws IOException, MetaException, ConfigurationException {
HiveConf conf = new HiveConf();
conf.setVar(METASTOREURIS, props.getProperty(HIVE_METASTORE_URIS, DEFAULT_METASTORE_URI));
if (props.getProperty(HIVE_METASTORE_AUTHE... | Get metastore client for the remote hive metastore. Supports kerberos based
authentication. Using kerberos requires user to get kerberos ticket and setup
keytab externally.
@param props hive configuration to use for connecting to the metastore
@return metastore client
@throws IOException indicates failure to read keyta... | getRemoteMetastoreClient | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/metastore/MetastoreProvider.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/metastore/MetastoreProvider.java | BSD-2-Clause |
public static void initHiveMetastoreClient(String hivePropsLocation) throws Exception {
// Connect to remote production Hive Metastore Client
hiveMetastoreClient = MetastoreProvider.getMetastoreClient(hivePropsLocation);
} | Utility class to provide Coral functionality to Coral Service. | initHiveMetastoreClient | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/utils/CoralProvider.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/utils/CoralProvider.java | BSD-2-Clause |
public static void initLocalMetastore() throws IOException, HiveException, MetaException {
// Create a temporary local metastore
conf = loadResourceHiveConf();
try {
// Delete existing local metastore if it exists
String tempDir = conf.get(CORAL_SERVICE_DIR);
LOGGER.info("Temp Workspace: ... | Utility class to provide Coral functionality to Coral Service. | initLocalMetastore | java | linkedin/coral | coral-service/src/main/java/com/linkedin/coral/coralservice/utils/CoralProvider.java | https://github.com/linkedin/coral/blob/master/coral-service/src/main/java/com/linkedin/coral/coralservice/utils/CoralProvider.java | BSD-2-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.