Exemplo n.º 1
0
def create_merge_table(context_id: str, command_id: str,
                       table_names: List[str]) -> str:
    """
    Parameters
    ----------
    context_id : str
        The id of the experiment
    command_id : str
        The id of the command that the merge table
    table_names: List[str]
        Its a list of names of the tables to be merged

    Returns
    ------
    str
        The name(string) of the created merge table in lower case.
    """
    validate_tables_can_be_merged(table_names)
    schema = common_actions.get_table_schema(table_names[0])
    merge_table_name = create_table_name("merge", command_id, context_id,
                                         node_config.identifier)
    table_info = TableInfo(merge_table_name, schema)
    merge_tables.create_merge_table(table_info)
    merge_tables.add_to_merge_table(merge_table_name, table_names)

    return merge_table_name
Exemplo n.º 2
0
def get_table_schema(table_name: str) -> str:
    """
    Parameters
    ----------
    table_name : str
    The name of the table

    Returns
    ------
    str(TableSchema)
        A TableSchema object in a jsonified format
    """
    schema = common_actions.get_table_schema(table_name)
    return schema.to_json()
Exemplo n.º 3
0
def _convert_udf2udfgen_arg(udf_argument: UDFArgument):
    if udf_argument.type == "literal":
        return udf_argument.value
    elif udf_argument.type == "table":
        name = udf_argument.value
        schema = get_table_schema(udf_argument.value)
        udf_generator_schema = [
            ColumnInfo(column.name, column.data_type) for column in schema.columns
        ]
        return TableInfo(name, udf_generator_schema)
    else:
        raise ValueError(
            "A udf argument can have one of the following types 'literal','table'."
        )
Exemplo n.º 4
0
def get_table_data(table_name: str) -> str:
    """
    Parameters
    ----------
    table_name : str
        The name of the table

    Returns
    ------
    str(TableData)
        An object of TableData in a jsonified format
    """
    schema = common_actions.get_table_schema(table_name)
    data = common_actions.get_table_data(table_name)
    return TableData(schema, data).to_json()
Exemplo n.º 5
0
def add_to_merge_table(merge_table_name: str, table_names: List[str]):
    non_existing_tables = get_non_existing_tables(table_names)
    table_infos = [TableInfo(name, get_table_schema(name)) for name in table_names]

    try:
        for name in table_names:
            MonetDB().execute(
                f"ALTER TABLE {merge_table_name} ADD TABLE {name.lower()}"
            )

    except pymonetdb.exceptions.OperationalError as exc:
        if str(exc).startswith("3F000"):
            raise IncompatibleSchemasMergeException(table_infos)
        elif str(exc).startswith("42S02"):
            raise TablesNotFound(non_existing_tables)
        else:
            raise exc