sampotools.api.gen_asd_from_table

sampotools.api.gen_asd_from_table(sql, uri)

Generates an ASD (Attribute Schema Description) from a select sql query, name of table, or view.

Supported Database is PostgreSQL.

Supported schema is public only and the recommended PostgreSQL data types are as follows:

database data type category

database data type

SAMPO

Remarks

Numeric Types

SMALLINT

INTEGER

REAL if NULL values exist

INTEGER

INTEGER

REAL if NULL values exist

BIGINT

INTEGER

REAL if NULL values exist

SMALLSERIAL

INTEGER

REAL if NULL values exist

SERIAL

INTEGER

REAL if NULL values exist

BIGSERIAL

INTEGER

REAL if NULL values exist

DECIMAL

REAL

REAL

REAL

DOUBLE PRECISION

REAL

NUMERIC

REAL

Monetary Types

MONEY

NOMINAL

Character Types

CHARACTER

NOMINAL

CHARACTER VARYING

NOMINAL

TEXT

NOMINAL

Date/Time Types

TIMESTAMP

DATE

TIMESTAMP WITH TIME ZONE

DATE

DATE

DATE

INTERVAL

DATE

TIME

NOMINAL

TIME WITH TIME ZONE

NOMINAL

Boolean Type

BOOL

NOMINAL

Enumerated Types

NOMINAL

Network Address Types

CIDR

NOMINAL

INET

NOMINAL

MACADDR

NOMINAL

Note

Some database data types not specified in this table may still create NOMINAL scale attributes in the output ASD. However, SAMPO may not be able to fully support those attributes in learning and prediction, thus it is not recommended to use those data types.

Parameters
sqlstr

SQL query, database table or view name. Table or column names with spaces in sql queries must be enclosed in double quotations.

uristr

Database connection URI.

Returns
asd_objectOrderedDict

Attribute schema. See ASD object.

Note

Checking whether the attribute scales and domains are properly generated is strongly recommended.

Examples

>>> from sampotools.api import gen_asd_from_table
>>> sql = 'SELECT * FROM fabhmerg_learn'
>>> connection_uri = 'postgresql://aapfuser@localhost:5432/testdb'
>>> asd_object = gen_asd_from_table(sql, connection_uri)