例: ODBCを使用したAdvanced SQL EngineへのAsterテーブルの読み込み - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - Advanced SQL Engine分析関数

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
2021年7月
Language
日本語
Last Update
2021-09-23
dita:mapPath
ja-JP/wnd1589838592459.ditamap
dita:ditavalPath
ja-JP/ayr1485454803741.ditaval
dita:id
B035-1206
Product Category
Software
Teradata Vantage
この例では、以下のコードを示します。
  • Aster Databaseでのテーブルの作成と挿入
  • テーブルを所有するAdvanced SQL Engineユーザーの作成
  • tptスクリプト
  • JobVariablesFile
  • tptスクリプトの実行

Aster Databaseでテーブルを作成、挿入するコード

このコードでは、トレーニング テーブル、aster_nb_trainerSCを作成、挿入し、トレーニング テーブルとNaive Bayes分類子関数を使用してモデル テーブル、aster_nb_modelSCを作成します。

/* Create training table */

DROP TABLE IF EXISTS aster_nb_trainerSC;

CREATE TABLE aster_nb_trainerSC (
  id     INT,
  year   INT,
  color  VARCHAR (100),
  type   VARCHAR (100),
  origin VARCHAR (100),
  stolen VARCHAR (100),
  PARTITION KEY (id)
);
/* Populate training table */

INSERT INTO aster_nb_trainerSC VALUES
  (1,3,'red','sports','domestic','Yes'),
  (2,9,'red','sports','domestic','No'),
  (3,1,'red','sports','domestic','Yes'),
  (4,8,'yellow','sports','domestic','No'),
  (5,2,'yellow','sports','imported','Yes');
/* Create model table from training table */

DROP TABLE IF EXISTS aster_nb_modelSC;

CREATE TABLE aster_nb_modelSC distribute by hash(class_nb) AS (
  SELECT * FROM naiveBayesReduce (
    ON (
      SELECT * FROM naiveBayesMap (
        ON aster_nb_trainerSC 
        Response ('stolen') 
        NumericInputs ('year') 
        CategoricalInputs ('color','origin','type')
      )
    ) PARTITION BY class_nb
  )
);

Advanced SQL Engineユーザーを作成するコード

CREATE USER sample_user AS
  PASSWORD = sample_user
  PERM = 10e6*(HASHAMP()+1);

GRANT ALL ON dbc TO sample_user;

tptスクリプト、astermodel.tpt

DEFINE JOB PRODUCT_SOURCE_LOAD
DESCRIPTION 'LOAD PRODUCT DEFINITION TABLE'
(
  DEFINE SCHEMA PRODUCT_SOURCE_SCHEMA
    DESCRIPTION 'PRODUCT INFORMATION SCHEMA'
    (
    class_nb VARCHAR(128),
    variable_nb VARCHAR(128),
    type_nb VARCHAR(128),
    category VARCHAR(32),
    cnt BIGINT,
    sum_nb FLOAT,
    sum_sq FLOAT,
    total_cnt BIGINT
    );

  STEP STEP_CREATE_DDL
  (
    APPLY
      ('DROP TABLE '||@TargetTable||';'),
      ('CREATE MULTISET TABLE '||@TargetTable||'(
         class_nb VARCHAR(128),
         variable_nb VARCHAR(128),
         type_nb VARCHAR(128),
         category VARCHAR(32),
         cnt BIGINT,
         sum_nb FLOAT,
         sum_sq FLOAT,
         total_cnt BIGINT) NO PRIMARY INDEX;
      ')
      TO OPERATOR ($DDL()[1]);
    );
    Step Insert Tables
    (
      APPLY
        ('Ins '||@TargetTable||'(
          :"class_nb"
          ,:"variable_nb"
          ,:"type_nb"
          ,:"category"
          ,:"cnt"
          ,:"sum_nb"
          ,:"sum_sq"
          ,:"total_cnt");'
        )
        TO OPERATOR ($LOAD()[1])

    SELECT * FROM OPERATOR ($ODBC(PRODUCT_SOURCE_SCHEMA)[1]);
  );
);

JobVariablesFile、attr.txt

DDLTdpid = 'td_host_name_or_ip'
,DDLUserName = 'alice'
,DDLUserPassword = 'alice'
,DDLErrorList = '[3807]'
,DDLPrivateLogName = 'DDL001S1'
,TargetTable = 'td_nb_modelsc'
,ODBCPrivateLogName = 'ODBC039P1'
,ODBCDSNName = 'shruti'
,TruncateData = 'Y'
,ODBCUserName = 'db_superuser'
,ODBCUserPassword = 'db_superuser'
,LOADPrivateLogName = 'ODBC039P1'
,LOADTDPID = 'td_host_name_or_ip'
,LOADUserName = 'alice'
,LOADUserPassword = 'alice'
,SelectStmt = 'SELECT * FROM aster_nb_modelsc;'
,LOADTargetTable = 'td_nb_modelsc'

tptスクリプトを実行するコマンド

tbuild -f aster_model.tpt -v attr.txt -j urr1