25.10.2016 Views

SAP HANA Predictive Analysis Library (PAL)

sap_hana_predictive_analysis_library_pal_en

sap_hana_predictive_analysis_library_pal_en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 4:<br />

Name intArgs doubleArgs stringArgs<br />

THREAD_NUMBER 1<br />

SUPPORT 0.2<br />

VAR_NAME hello<br />

2.5.2 Exception Handling<br />

Exceptions thrown by a <strong>PAL</strong> function can be caught by the exception handler in a SQLScript procedure with<br />

AFL error code 423.<br />

The following shows an example of handling the exceptions thrown by an ARIMA function. In the example, you<br />

are generating the "DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIMAXTRAIN_PROC procedure to call an ARIMA function, whose input<br />

data table is empty. You create a SQLScript procedure "DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIIMAX_NON_EXCEPTION_PROC<br />

which calls the "DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIMAXTRAIN_PROC procedure. When you call the<br />

"DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIIMAX_NON_EXCEPTION_PROC procedure, the exception handler in the procedure will<br />

catch the errors thrown by the function.<br />

SET SCHEMA DM_<strong>PAL</strong>;<br />

DROP TYPE <strong>PAL</strong>_ARIMAX_DATA_T;<br />

CREATE TYPE <strong>PAL</strong>_ARIMAX_DATA_T AS TABLE(<br />

"TIMESTAMP" INTEGER,<br />

"X1" DOUBLE,<br />

"Xreg" DOUBLE<br />

);<br />

DROP TYPE <strong>PAL</strong>_ARIMAX_CONTROL_T;<br />

CREATE TYPE <strong>PAL</strong>_ARIMAX_CONTROL_T AS TABLE(<br />

"NAME" VARCHAR (50),<br />

"INTARGS" INTEGER,<br />

"DOUBLEARGS" DOUBLE,<br />

"STRINGARGS" VARCHAR (100)<br />

);<br />

DROP TYPE <strong>PAL</strong>_ARIMAX_MODEL_T;<br />

CREATE TYPE <strong>PAL</strong>_ARIMAX_MODEL_T AS TABLE(<br />

"NAME" VARCHAR (50),<br />

"VALUE" VARCHAR (5000)<br />

);<br />

DROP TABLE <strong>PAL</strong>_ARIMAX_PDATA_TBL;<br />

CREATE COLUMN TABLE <strong>PAL</strong>_ARIMAX_PDATA_TBL("POSITION" INT, "SCHEMA_NAME"<br />

NVARCHAR(256), "TYPE_NAME" NVARCHAR(256), "PARAMETER_TYPE" VARCHAR(7));<br />

INSERT INTO <strong>PAL</strong>_ARIMAX_PDATA_TBL VALUES (1,'DM_<strong>PAL</strong>', '<strong>PAL</strong>_ARIMAX_DATA_T','IN');<br />

INSERT INTO <strong>PAL</strong>_ARIMAX_PDATA_TBL VALUES(2,'DM_<strong>PAL</strong>', '<strong>PAL</strong>_ARIMAX_CONTROL_T','IN');<br />

INSERT INTO <strong>PAL</strong>_ARIMAX_PDATA_TBL VALUES(3,'DM_<strong>PAL</strong>', '<strong>PAL</strong>_ARIMAX_MODEL_T','OUT');<br />

CALL SYS.AFLLANG_WRAPPER_PROCEDURE_DROP('DM_<strong>PAL</strong>', '<strong>PAL</strong>_ARIMAXTRAIN_PROC');<br />

CALL SYS.AFLLANG_WRAPPER_PROCEDURE_CREATE('AFL<strong>PAL</strong>', 'ARIMATRAIN', 'DM_<strong>PAL</strong>',<br />

'<strong>PAL</strong>_ARIMAXTRAIN_PROC',<strong>PAL</strong>_ARIMAX_PDATA_TBL);<br />

DROP PROCEDURE "DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIIMAX_NON_EXCEPTION_PROC;<br />

CREATE PROCEDURE <strong>PAL</strong>_ARIIMAX_NON_EXCEPTION_PROC(IN training_data<br />

<strong>PAL</strong>_ARIMAX_DATA_T, IN para_args <strong>PAL</strong>_ARIMAX_CONTROL_T)<br />

LANGUAGE SQLSCRIPT AS<br />

BEGIN<br />

-- used to catch exceptions<br />

DECLARE EXIT HANDLER FOR SQLEXCEPTION<br />

SELECT ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE FROM DUMMY;<br />

CALL "DM_<strong>PAL</strong>".<strong>PAL</strong>_ARIMAXTRAIN_PROC(:training_data, :para_args, result_model);<br />

END;<br />

DROP TABLE <strong>PAL</strong>_ARIMAX_DATA_TBL;<br />

12 P U B L I C<br />

<strong>SAP</strong> <strong>HANA</strong> <strong>Predictive</strong> <strong>Analysis</strong> <strong>Library</strong> (<strong>PAL</strong>)<br />

Getting Started with <strong>PAL</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!