Teradataml:在Teradataml中运行查询时如何使用temp db?

时间:2019-09-26 18:33:01

标签: python teradata

teradataml是否支持临时表的临时数据库,执行查询时创建的视图? 该如何使用?是否需要任何特定的配置?

1 个答案:

答案 0 :(得分:0)

create_context(host=None, username=None, password=None, tdsqlengine=None, temp_database_name=None, logmech=None)
    DESCRIPTION:
        Creates a connection to the Teradata Vantage using the teradatasql + teradatasqlalchemy DBAPI and dialect combination.
        Users can pass all required parameters (host, username, password) for establishing a connection to Vantage,
        or pass a sqlalchemy engine to the tdsqlengine parameter to override the default DBAPI and dialect combination.

        temp_database_name:
            Optional Argument.
            Specifies the temporary database name where temporary tables, views will be created.
            Types: str

在运行以下示例之前,请确保temp_database_name参数中指定的数据库存在,并且相应的用户具有对具有Grant选项的函数的执行访问权限,并在具有Grant选项的输入表上选择访问权限。这可以通过运行:

grant execute function on <function name> to <user> with grant option;
grant select on <input table> to <temp db user> with grant option;

示例:

import teradataml
from teradataml.context.context import *
from teradataml.dataframe.dataframe import DataFrame
from teradataml.analytics.mle.XGBoost import XGBoost
from teradataml.analytics.mle.XGBoostPredict import XGBoostPredict
from teradataml.options.display import display
display.print_sqlmr_query = True

con = create_context(host="hostname", username="user", password="password",temp_database_name="mytemp")

housing_train_binary = DataFrame.from_table("housing_train_binary")

xgboostmodel = XGBoost(data=housing_train_binary,
                         id_column='sn',
                         formula=" homestyle ~ driveway +  recroom +  fullbase +  gashw +  airco +  prefarea ",
                         num_boosted_trees=2,
                         loss_function='SOFTMAX',
                         prediction_type='CLASSIFICATION',
                         reg_lambda=1.0,
                         shrinkage_factor=0.1,
                         column_subsampling=1.0,
                         iter_num=10,
                         min_node_size=1,
                         max_depth=12,
                         variance=0.0,
                         seed=1,
                         data_sequence_column=['sn', 'homestyle']
                         )
xgboostmodel                        

housing_test_binary = DataFrame.from_table("housing_test_binary")

xgpredict = XGBoostPredict(newdata=housing_test_binary,
                                object=xgboostmodel,
                                object_order_column=['tree_id', 'iter', 'class_num'],
                                id_column='sn',
                                terms='homestyle',
                                num_boosted_trees=1
                                )

xgboostpredict