Skip to content

Commit

Permalink
Use name that avoid compiler class with overload
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Dec 16, 2024
1 parent 1a17091 commit f7f5bc0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,24 +532,24 @@ private static Field convertField(
(Object) null /* Cast to avoid deprecated JsonNode constructor. */);
}

static TableSchema toTableSchema(Schema schema) {
return toTableSchema(schema, true);
static TableSchema fromGenericAvroSchema(Schema schema) {
return fromGenericAvroSchema(schema, true);
}

static TableSchema toTableSchema(Schema schema, Boolean useAvroLogicalTypes) {
static TableSchema fromGenericAvroSchema(Schema schema, Boolean useAvroLogicalTypes) {
verify(
schema.getType() == Type.RECORD,
"Expected Avro schema type RECORD, not %s",
schema.getType());

List<TableFieldSchema> fields =
schema.getFields().stream()
.map(f -> toTableFieldSchema(f, useAvroLogicalTypes))
.map(f -> fromAvroFieldSchema(f, useAvroLogicalTypes))
.collect(Collectors.toList());
return new TableSchema().setFields(fields);
}

private static TableFieldSchema toTableFieldSchema(
private static TableFieldSchema fromAvroFieldSchema(
Schema.Field avrofield, Boolean useAvroLogicalTypes) {
Schema fieldSchema = avrofield.schema();
TableFieldSchema field;
Expand Down Expand Up @@ -660,7 +660,7 @@ private static TableFieldSchema typedTableFieldSchema(Schema type, Boolean useAv
case RECORD:
List<TableFieldSchema> recordFields =
type.getFields().stream()
.map(f -> toTableFieldSchema(f, useAvroLogicalTypes))
.map(f -> fromAvroFieldSchema(f, useAvroLogicalTypes))
.collect(Collectors.toList());
return new TableFieldSchema().setType("RECORD").setFields(recordFields);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ public static org.apache.avro.Schema toGenericAvroSchema(TableSchema tableSchema
}

/** Convert an Avro {@link org.apache.avro.Schema} to a BigQuery {@link TableSchema}. */
public static TableSchema toTableSchema(org.apache.avro.Schema schema) {
return toTableSchema(schema, false);
public static TableSchema fromGenericAvroSchema(org.apache.avro.Schema schema) {
return fromGenericAvroSchema(schema, false);
}

/** Convert an Avro {@link org.apache.avro.Schema} to a BigQuery {@link TableSchema}. */
public static TableSchema toTableSchema(
public static TableSchema fromGenericAvroSchema(
org.apache.avro.Schema schema, Boolean useAvroLogicalTypes) {
return BigQueryAvroUtils.toTableSchema(schema, useAvroLogicalTypes);
return BigQueryAvroUtils.fromGenericAvroSchema(schema, useAvroLogicalTypes);
}

/** Convert a BigQuery {@link TableSchema} to Avro {@link org.apache.avro.Schema}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,71 +698,71 @@ public void testConvertAvroSchemaToBigQuerySchema() {
Schema avroSchema = avroSchema(f -> f.type().booleanType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("BOOLEAN").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// nullable
Schema avroSchema = avroSchema(f -> f.type().optional().booleanType());
TableSchema expected = tableSchema(f -> f.setType("BOOLEAN").setMode("NULLABLE"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// array
Schema avroSchema = avroSchema(f -> f.type().array().items().booleanType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("BOOLEAN").setMode("REPEATED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// int
Schema avroSchema = avroSchema(f -> f.type().intType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// long
Schema avroSchema = avroSchema(f -> f.type().longType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// float
Schema avroSchema = avroSchema(f -> f.type().floatType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("FLOAT").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// double
Schema avroSchema = avroSchema(f -> f.type().doubleType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("FLOAT").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// bytes
Schema avroSchema = avroSchema(f -> f.type().bytesType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
// string
Schema avroSchema = avroSchema(f -> f.type().stringType().noDefault());
TableSchema expected = tableSchema(f -> f.setType("STRING").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}

{
Expand All @@ -773,8 +773,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("NUMERIC").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -786,8 +786,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
tableSchema(f -> f.setType("NUMERIC").setPrecision(29L).setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -799,8 +799,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
tableSchema(f -> f.setType("NUMERIC").setPrecision(10L).setScale(9L).setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -811,8 +811,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("BIGNUMERIC").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -824,8 +824,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
tableSchema(f -> f.setType("BIGNUMERIC").setPrecision(38L).setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -838,8 +838,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
f -> f.setType("BIGNUMERIC").setPrecision(39L).setScale(38L).setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("BYTES").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -849,8 +849,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("DATE").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -860,8 +860,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("TIME").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -871,8 +871,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("TIME").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -883,8 +883,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("DATETIME").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -895,8 +895,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("DATETIME").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -907,8 +907,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("TIMESTAMP").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -919,8 +919,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("TIMESTAMP").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("INTEGER").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -931,8 +931,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("GEOGRAPHY").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("STRING").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand All @@ -942,8 +942,8 @@ public void testConvertAvroSchemaToBigQuerySchema() {
TableSchema expected = tableSchema(f -> f.setType("JSON").setMode("REQUIRED"));
TableSchema expectedRaw = tableSchema(f -> f.setType("STRING").setMode("REQUIRED"));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.toTableSchema(avroSchema, false));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
assertEquals(expectedRaw, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema, false));
}

{
Expand Down Expand Up @@ -973,7 +973,7 @@ public void testConvertAvroSchemaToBigQuerySchema() {
.setMode("REQUIRED")
.setFields(Lists.newArrayList(subInteger, subFloat)));

assertEquals(expected, BigQueryAvroUtils.toTableSchema(avroSchema));
assertEquals(expected, BigQueryAvroUtils.fromGenericAvroSchema(avroSchema));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4111,7 +4111,7 @@ public void testUpsertAndDeleteGenericRecords() throws Exception {
.requiredString("sqn")
.endRecord();

TableSchema tableSchema = BigQueryAvroUtils.toTableSchema(avroSchema);
TableSchema tableSchema = BigQueryAvroUtils.fromGenericAvroSchema(avroSchema);

Table fakeTable = new Table();
TableReference ref =
Expand Down

0 comments on commit f7f5bc0

Please sign in to comment.