Exemplo n.º 1
0
 def get_primary_key_from_path(self, column_names: Dict[str, Tuple[str,
                                                                   str]],
                               path: List[str]) -> str:
     if path and len(path) == 1:
         field = path[0]
         if not is_airbyte_column(field):
             if "type" in self.properties[field]:
                 property_type = self.properties[field]["type"]
             else:
                 property_type = "object"
             if is_number(property_type) or is_object(property_type):
                 # some destinations don't handle float columns (or complex types) as primary keys, turn them to string
                 return f"cast({column_names[field][0]} as {jinja_call('dbt_utils.type_string()')})"
             else:
                 return column_names[field][0]
         else:
             # using an airbyte generated column
             return f"cast({field} as {jinja_call('dbt_utils.type_string()')})"
     else:
         if path:
             raise ValueError(
                 f"Unsupported nested path {'.'.join(path)} for stream {self.stream_name}"
             )
         else:
             raise ValueError(
                 f"No path specified for stream {self.stream_name}")
Exemplo n.º 2
0
 def cast_property_type(self, property_name: str, column_name: str,
                        jinja_column: str) -> str:
     definition = self.properties[property_name]
     if "type" not in definition:
         print(
             f"WARN: Unknown type for column {property_name} at {self.current_json_path()}"
         )
         return column_name
     elif is_array(definition["type"]):
         return self.cast_property_type_as_array(property_name, column_name)
     elif is_object(definition["type"]):
         sql_type = self.cast_property_type_as_object(
             property_name, column_name)
     # Treat simple types from narrower to wider scope type: boolean < integer < number < string
     elif is_boolean(definition["type"]):
         cast_operation = jinja_call(f"cast_to_boolean({jinja_column})")
         return f"{cast_operation} as {column_name}"
     elif is_integer(definition["type"]):
         sql_type = jinja_call("dbt_utils.type_bigint()")
     elif is_number(definition["type"]):
         sql_type = jinja_call("dbt_utils.type_float()")
     elif is_string(definition["type"]):
         sql_type = jinja_call("dbt_utils.type_string()")
     else:
         print(
             f"WARN: Unknown type {definition['type']} for column {property_name} at {self.current_json_path()}"
         )
         return column_name
     return f"cast({column_name} as {sql_type}) as {column_name}"