Skip to content

s3_to_redshift fix json iterators #5

Description

@szeevs

Accessing keys and values of the json schema is incorrect.
Change the code to:

def create_if_not_exists(self, schema, pg_hook, temp=False):
        output = ''
        for item in schema:
            k = "{quote}{key}{quote}".format(quote='"', key=item)
            field = ' '.join([k, schema[item]])
            if isinstance(self.sortkey, str) and self.sortkey == item:
                field += ' sortkey'
            output += field
            output += ', '
            ....

And also here:

def reconcile_schemas(self, schema, pg_hook):
        pg_query = \
            """
            SELECT column_name, udt_name
            FROM information_schema.columns
            WHERE table_schema = '{0}' AND table_name = '{1}';
            """.format(self.redshift_schema, self.table)
        pg_schema = dict(pg_hook.get_records(pg_query))
        incoming_keys = [column for column in schema]
        diff = list(set(incoming_keys) - set(pg_schema.keys()))
        print('diff {}'.format(diff))
        ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions