Loading...

verticapy.sql.isflextable

verticapy.sql.isflextable(table_name: str, schema: str) bool

Checks if the input relation is a flextable.

Parameters

table_name: str

Name of the table to check.

schema: str

Table schema.

Returns

bool

True if the relation is a flex table.

Examples

Create a JSON file:

import json

data = {
    "column1": {
        "subcolumn1A": "value1A",
        "subcolumn1B": "value1B",
    },
    "column2": {
        "subcolumn2A": "value2A",
        "subcolumn2B": "value2B",
    }
}


json_string = json.dumps(data, indent=4)

with open("nested_columns.json", "w") as json_file:
    json_file.write(str(json_string))

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from verticapy are used as intended without interfering with functions from other libraries.

We create a temporary schema:

vp.create_schema("temp")
Out[6]: False

We injest the JSON file:

vdf = vp.read_json(
    "nested_columns.json",
    schema = "temp",
    table_name = "test",
    flatten_maps = False,
)

The table "temp"."test" has been successfully created.

Then check if the table is a flex table:

from verticapy.sql import isflextable

isflextable(table_name = "test", schema = "temp")
Out[9]: False

We drop the temporary table.

vp.drop("temp.test")
Out[10]: True

Hint

Flex tables can be used to identify all the data types needed to ingest the file and can also be employed to flatten a nested JSON file. Explore all the flex functions to understand the possibilities.

See also

compute_flextable_keys() : : Computes the flex table keys.
compute_vmap_keys() : Computes the vmap most frequent keys.
isvmap() : Checks if the input column is a VMap.