You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/07/04 12:23:17 UTC

[GitHub] [nifi] turcsanyip commented on a change in pull request #3570: Fix for NIFI-6422

turcsanyip commented on a change in pull request #3570: Fix for NIFI-6422
URL: https://github.com/apache/nifi/pull/3570#discussion_r300373423
 
 

 ##########
 File path: nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/bigquery/BigQueryUtils.java
 ##########
 @@ -37,29 +38,51 @@
     private final static Type gsonSchemaType = new TypeToken<List<Map>>() { }.getType();
 
     public static Field mapToField(Map fMap) {
-        String typeStr = fMap.get("type").toString();
+        String typeStr = fMap.get("type").toString().toUpperCase();
         String nameStr = fMap.get("name").toString();
-        String modeStr = fMap.get("mode").toString();
+        String modeStr;
+        if(fMap.containsKey("mode")) {
+        	modeStr = fMap.get("mode").toString();
+        } else {
+        	modeStr = Mode.NULLABLE.name();
+        }
         LegacySQLTypeName type = null;
+        List<Field> subFields = new ArrayList<>();
 
-        if (typeStr.equals("BOOLEAN")) {
-            type = LegacySQLTypeName.BOOLEAN;
-        } else if (typeStr.equals("STRING")) {
-            type = LegacySQLTypeName.STRING;
-        } else if (typeStr.equals("BYTES")) {
-            type = LegacySQLTypeName.BYTES;
-        } else if (typeStr.equals("INTEGER")) {
-            type = LegacySQLTypeName.INTEGER;
-        } else if (typeStr.equals("FLOAT")) {
-            type = LegacySQLTypeName.FLOAT;
-        } else if (typeStr.equals("TIMESTAMP") || typeStr.equals("DATE")
-                || typeStr.equals("TIME") || typeStr.equals("DATETIME")) {
-            type = LegacySQLTypeName.TIMESTAMP;
-        } else if (typeStr.equals("RECORD")) {
-            type = LegacySQLTypeName.RECORD;
+        switch(typeStr) {
+        case "BOOLEAN":
+        	type = LegacySQLTypeName.BOOLEAN;
+        	break;
+        case "STRING":
+        	type = LegacySQLTypeName.STRING;
+        	break;
+        case "BYTES":
+        	type = LegacySQLTypeName.BYTES;
+        	break;
+        case "INTEGER":
+        	type = LegacySQLTypeName.INTEGER;
+        	break;
+        case "FLOAT":
+        	type = LegacySQLTypeName.FLOAT;
+        	break;
+        case "RECORD":
+            List<Map> fields = (List<Map>) fMap.get("fields");
+        	type = LegacySQLTypeName.RECORD;
+        	subFields.addAll(listToFields(fields));
+        	break;
+        case "TIMESTAMP":
+        case "DATE":
+        case "TIME":
+        case "DATETIME":
+        	type = LegacySQLTypeName.TIMESTAMP;
+        	break;
+        default:
+        	throw new BadTypeNameException(String.format("You used invalid BigQuery type \"%s\" in declaration of\n%s\n"
+        			+ "Supported types are \"BOOLEAN, STRING, BYTES, INTEGER, FLOAT, RECORD, TIMESTAMP, DATE, TIME, DATETIME\"", 
+        			typeStr, fMap));
         }
 
-        return Field.newBuilder(nameStr, type).setMode(Field.Mode.valueOf(modeStr)).build();
+        return Field.newBuilder(nameStr, type, subFields.toArray(new Field[subFields.size()])).setMode(Field.Mode.valueOf(modeStr)).build();
     }
 
     public static List<Field> listToFields(List<Map> m_fields) {
 
 Review comment:
   I see it is an old code, but could you please rename this parameter to 'fields'? (or something similar, just remove the m_ prefix)
   Please also fix the unchecked assignment in this method too (new ArrayList<>).

----------------------------------------------------------------
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


With regards,
Apache Git Services