private Object getValueFromField ( String fieldPath , Field field ) { LOG . trace ( "Visiting Field Path '{}' of type '{}'" , fieldPath , field . getType ( ) ) ; switch ( field . getType ( ) ) { case LIST : //REPEATED List < Field > listField = field . getValueAsList ( ) ; //Convert the list to map with indices as key and Field as value (Map<Integer, Field>) Map < Integer , Field > fields = IntStream . range ( 0 , listField . size ( ) ) . boxed ( ) . collect ( Collectors . toMap ( Function . identity ( ) , listField :: get ) ) ; //filter map to remove fields with null value fields = fields . entrySet ( ) . stream ( ) . filter ( e -> e . getValue ( ) . getValue ( ) != null ) . collect ( Collectors . toMap ( Map . Entry :: getKey , Map . Entry :: getValue ) ) ; //now use the map index to generate field path and generate object for big query write return fields . entrySet ( ) . stream ( ) . map ( e -> getValueFromField ( fieldPath + "[" + e . getKey ( ) + "]" , e . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ; case MAP : case LIST_MAP : //RECORD return field . getValueAsMap ( ) . entrySet ( ) . stream ( ) . filter ( me -> me . getValue ( ) . getValue ( ) != null ) . collect ( Collectors . toMap ( Map . Entry :: getKey , e -> getValueFromField ( fieldPath + "/" + e . getKey ( ) , e . getValue ( ) ) ) ) ; case DATE : return dateFormat . format ( field . getValueAsDate ( ) ) ; case TIME : return timeFormat . format ( field . getValueAsTime ( ) ) ; case DATETIME : return dateTimeFormat . format ( field . getValueAsDatetime ( ) ) ; case BYTE_ARRAY : return Base64 . getEncoder ( ) . encodeToString ( field . getValueAsByteArray ( ) ) ; case DECIMAL : case BYTE : case CHAR : case FILE_REF : throw new IllegalArgumentException ( Utils . format ( Errors . BIGQUERY_12 . getMessage ( ) , fieldPath , field . getType ( ) ) ) ; default : //Boolean -> Map to Boolean in big query //Float, Double -> Map to Float in big query //String -> maps to String in big query //Short, Integer, Long -> Map to integer in big query return field . getValue ( ) ; } }
Convert the sdc Field to an object for row content