Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.beam.sdk.annotations.Internal;
import org.apache.beam.sdk.extensions.sql.meta.provider.bigquery.BeamBigQuerySqlDialect;
Expand Down Expand Up @@ -180,12 +182,15 @@ private static RelDataType toCalciteStructType(

private static List<String> getFieldNameList(List<StructField> fields) {
ImmutableList.Builder<String> b = ImmutableList.builder();
Set<String> usedName = new HashSet<>();
for (int i = 0; i < fields.size(); i++) {
String name = fields.get(i).getName();
if ("".equals(name)) {
name = "$col" + i; // avoid empty field names because Beam does not allow duplicate names
// Follow the same way that BigQuery handles unspecified or duplicate field name
if ("".equals(name) || name.startsWith("_field_") || usedName.contains(name)) {
name = "_field_" + (i + 1); // BigQuery uses 1-based default field name
}
b.add(name);
usedName.add(name);
}
return b.build();
}
Expand Down