Loading...

verticapy.sql.isvmap#

verticapy.sql.isvmap(expr: str | StringSQL, column: str) bool#

Checks if the input column is a VMap.

Parameters#

expr: SQLRelation

Any relation or expression. If you enter an expression, you must enclose it in parentheses and provide an alias.

column: str

Name of the column to check.

Returns#

bool

True if the column is a VMap.

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,
)

Checking if column1 is a vmap:

from verticapy.sql import isvmap

isvmap("temp.test", "column1")
Out[9]: True

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.
isflextable() : Checks if the input relation is a flextable.