Пример #1
0
def create_new_yaml(suffix, input_file=sys.stdin):

    schema = RedShiftLogSchema(yaml.load(input_file))
    for table_name in schema.tables().keys():
        schema.table_rename(
            table_name,
            '{original_name}{suffix}'.format(original_name=table_name,
                                             suffix=suffix))
    return yaml.dump(schema.schema(), default_flow_style=False)
Пример #2
0
def create_new_yaml(suffix, input_file=sys.stdin):

    schema = RedShiftLogSchema(yaml.load(input_file))
    for table_name in schema.tables().keys():
        schema.table_rename(
            table_name, '{original_name}{suffix}'.format(
                original_name=table_name,
                suffix=suffix
            )
        )
    return yaml.dump(schema.schema(), default_flow_style=False)
Пример #3
0
        help="path to schema file into which new table is merged"
    )
    args = parser.parse_args()
    args.foreign.sort()
    return args


if __name__ == "__main__":
    args = get_cmd_line_args()

    schema = RedShiftLogSchema()
    version = 0

    if args.merge_with_schema:
        with open(args.merge_with_schema, 'r') as yaml_file:
            schema = RedShiftLogSchema(yaml.safe_load(yaml_file))
            if schema.get_table(args.table) is not None:
                schema.table_delete(args.table)
            version = schema.version_get()

    sm = RedShiftSchemaMaker(exclude=args.exclude, prune=args.prune)
    for line in fileinput.input('-'):
        process_row(sm, simplejson.loads(line), args)

    table = sm.mk_table(sm.schema, args.table, args.source, args.source_type,
                        add_source_filename=args.add_source_filename)
    schema.table_add(args.table, table[args.table])
    schema.version_set(version + 1)
    sys.stdout.write(schema.header())
    sys.stdout.write(yaml.dump(schema.schema(), default_flow_style=False))
Пример #4
0
    args.foreign.sort()
    return args


if __name__ == "__main__":
    args = get_cmd_line_args()

    schema = RedShiftLogSchema()
    version = 0

    if args.merge_with_schema:
        with open(args.merge_with_schema, 'r') as yaml_file:
            schema = RedShiftLogSchema(yaml.safe_load(yaml_file))
            if schema.get_table(args.table) is not None:
                schema.table_delete(args.table)
            version = schema.version_get()

    sm = RedShiftSchemaMaker(exclude=args.exclude, prune=args.prune)
    for line in fileinput.input('-'):
        process_row(sm, simplejson.loads(line), args)

    table = sm.mk_table(sm.schema,
                        args.table,
                        args.source,
                        args.source_type,
                        add_source_filename=args.add_source_filename)
    schema.table_add(args.table, table[args.table])
    schema.version_set(version + 1)
    sys.stdout.write(schema.header())
    sys.stdout.write(yaml.dump(schema.schema(), default_flow_style=False))