You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/08/12 18:35:20 UTC

[GitHub] [beam] apilloud commented on a change in pull request #12550: Follow the same way that BigQuery handles unspecified or duplicate ZetaSQL STRUCT field name

apilloud commented on a change in pull request #12550:
URL: https://github.com/apache/beam/pull/12550#discussion_r469461524



##########
File path: sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSqlCalciteTranslationUtils.java
##########
@@ -180,12 +182,19 @@ 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) || usedName.contains(name)) {

Review comment:
       This does not actually match the behavior of BigQuery. To match BigQuery you should remove the `HashSet` and instead replace anything starting with `_field_` with the correct index for that column.
   
   (In BigQuery, this condition would be `"".equals(name) || name.startsWith("_field_")`)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org