コード例 #1
0
def create_componentized_files(sql_json):
    matview_name = sql_json["final_name"]
    matview_temp_name = matview_name + "_temp"
    filename_base = os.path.join(DEST_FOLDER, COMPONENT_DIR,
                                 sql_json["final_name"])

    create_table = make_temp_table_create(matview_name, matview_temp_name)
    write_sql_file(create_table, filename_base + "__create")

    insert_into_table = make_table_inserts(matview_temp_name, matview_name,
                                           GLOBAL_ARGS.chunk_count)
    write_sql_file(insert_into_table, filename_base + "__inserts")

    sql_strings = make_rename_sql(matview_name)
    write_sql_file(sql_strings, filename_base + "__renames")

    sql_strings = make_modification_sql(matview_name, GLOBAL_ARGS.quiet)
    write_sql_file(sql_strings, filename_base + "__mods")

    sql_strings = make_table_drops(matview_name)
    write_sql_file(sql_strings, filename_base + "__drops")

    sql_strings = make_matview_empty(matview_name, GLOBAL_ARGS.chunk_count)
    write_sql_file(sql_strings, filename_base + "__empty")

    sql_strings = make_read_indexes(matview_name)
    write_sql_file(sql_strings, filename_base + "__indexes")

    sql_strings = make_read_constraints(matview_name)
    write_sql_file(sql_strings, filename_base + "__constraints")
コード例 #2
0
def create_componentized_files(sql_json):
    table_name = sql_json["final_name"]
    table_temp_name = table_name + "_temp"
    filename_base = os.path.join(DEST_FOLDER, COMPONENT_DIR, sql_json["final_name"])

    create_table = make_table_create(table_name)
    write_sql_file(create_table, filename_base + "__create")

    insert_into_table = make_table_inserts(table_name, GLOBAL_ARGS.chunk_count)
    write_sql_file(insert_into_table, filename_base + "__inserts")

    create_indexes, rename_old_indexes, rename_new_indexes = make_indexes_sql(
        sql_json, table_temp_name, UNIQUE_STRING, False, GLOBAL_ARGS.quiet
    )
    write_sql_file(create_indexes, filename_base + "__indexes")

    sql_strings = make_rename_sql(table_name, rename_old_indexes, rename_new_indexes)
    write_sql_file(sql_strings, filename_base + "__renames")

    sql_strings = make_modification_sql(table_name, GLOBAL_ARGS.quiet)
    write_sql_file(sql_strings, filename_base + "__mods")

    sql_strings = make_table_drops(table_name)
    write_sql_file(sql_strings, filename_base + "__drops")

    sql_strings = make_matview_empty(table_name, GLOBAL_ARGS.chunk_count)
    write_sql_file(sql_strings, filename_base + "__empty")
コード例 #3
0
def create_all_sql_strings(sql_json):
    """ Desired ordering of steps for final SQL:
        1. Drop existing "_temp" and "_old" matviews
        2. Create new matview
        3. analyze verbose <matview>
    """
    final_sql_strings = []

    matview_name = sql_json["final_name"]

    final_sql_strings.extend(make_matview_drops(matview_name))
    final_sql_strings.append("")
    final_sql_strings.extend(make_matview_create(matview_name, sql_json["matview_sql"]))

    final_sql_strings.append("")
    final_sql_strings.extend(make_modification_sql(matview_name, GLOBAL_ARGS.quiet))
    return final_sql_strings
コード例 #4
0
def create_componentized_files(sql_json):
    filename_base = os.path.join(DEST_FOLDER, COMPONENT_DIR,
                                 sql_json["final_name"])
    index_dir_path = os.path.join(filename_base, "batch_indexes/")

    matview_name = sql_json["final_name"]
    matview_temp_name = matview_name + "_temp"

    create_indexes, rename_old_indexes, rename_new_indexes = make_indexes_sql(
        sql_json, matview_temp_name, UNIQUE_STRING, True, GLOBAL_ARGS.quiet)
    create_stats, rename_old_stats, rename_new_stats = make_stats_sql(
        sql_json, matview_temp_name, UNIQUE_STRING)

    sql_strings = make_matview_drops(matview_name)
    write_sql_file(sql_strings, filename_base + "__drops")

    sql_strings = make_matview_create(matview_name, sql_json["matview_sql"])
    write_sql_file(sql_strings, filename_base + "__matview")

    indexes_and_stats = create_indexes + create_stats
    write_sql_file(indexes_and_stats, filename_base + "__indexes")

    if GLOBAL_ARGS.batch_indexes > 1:
        if not os.path.exists(index_dir_path):
            os.makedirs(index_dir_path)
        for i, index_block in enumerate(
                split_indexes_chunks(indexes_and_stats,
                                     GLOBAL_ARGS.batch_indexes)):
            write_sql_file(index_block, index_dir_path + "group_{}".format(i))

    sql_strings = make_modification_sql(matview_name, GLOBAL_ARGS.quiet)
    write_sql_file(sql_strings, filename_base + "__mods")

    sql_strings = make_rename_sql(matview_name, rename_old_indexes,
                                  rename_old_stats, rename_new_indexes,
                                  rename_new_stats)
    write_sql_file(sql_strings, filename_base + "__renames")

    if "refresh" in sql_json and sql_json["refresh"] is True:
        if GLOBAL_ARGS.no_data:
            sql_strings = make_matview_refresh(matview_temp_name, "")
        else:
            sql_strings = make_matview_refresh(matview_name)
        write_sql_file(sql_strings, filename_base + "__refresh")
コード例 #5
0
def create_all_sql_strings(sql_json):
    """Desired ordering of steps for final SQL:
    1. Drop existing "_temp" and "_old" matviews
    2. Create new matview
    3. Create indexes for new matview
    4. (optional) Cluster matview on index
    5. analyze verbose <matview>
    6. Rename existing matview, append with _old
    7. Rename all existing matview indexes to avoid name collisions
    8. Rename new matview
    9. Rename new matview indexes
    """
    final_sql_strings = []

    matview_name = sql_json["final_name"]
    matview_temp_name = matview_name + "_temp"

    create_indexes, rename_old_indexes, rename_new_indexes = make_indexes_sql(
        sql_json, matview_temp_name, UNIQUE_STRING, True, GLOBAL_ARGS.quiet)
    create_stats, rename_old_stats, rename_new_stats = make_stats_sql(
        sql_json, matview_temp_name, UNIQUE_STRING)

    final_sql_strings.extend(make_matview_drops(matview_name))
    final_sql_strings.append("")
    final_sql_strings.extend(
        make_matview_create(matview_name, sql_json["matview_sql"]))

    final_sql_strings.append("")
    final_sql_strings += create_indexes
    final_sql_strings.append("")
    final_sql_strings += create_stats
    final_sql_strings.append("")
    if GLOBAL_ARGS.no_data:
        final_sql_strings.extend(
            [TEMPLATE["refresh_matview"].format("", matview_name), ""])
    final_sql_strings.extend(
        make_rename_sql(matview_name, rename_old_indexes, rename_old_stats,
                        rename_new_indexes, rename_new_stats))
    final_sql_strings.append("")
    final_sql_strings.extend(
        make_modification_sql(matview_name, GLOBAL_ARGS.quiet))
    return final_sql_strings