CREATE DATABASE DB1 SYSTEM USER PASSWORD Initial1;
alter system start database DB1;
namespace HANAGoogleSheets;
@Schema : 'GOOGLE'
context Trips
{
type tString : String(3);
type sString : String(20);
type mString : String (50);
type lString : String(150);
/* An Entity becomes a table*/
entity Employee {
key id : Integer;
firstName : mString;
lastName : mString;
username : sString;
homeCountry : mString;
};
entity Trip {
key id : Integer;
fromDate : LocalDate; //2016-01-02
toDate : LocalDate;
destination : mString;
description : lString;
approver : Association to Employee on approver.username = traveller;
traveller : sString;
approver_uname : sString;
};
//The Predictive Analytic Library does not currently support the decimal data type. The decimal needs to be "Double" (BinaryFloat in CDS)
// or can be converted later using the following entries in the signature table:
//(-2, '_SYS_AFL', 'CAST_DECIMAL_TO_DOUBLE', 'INOUT');
//(-1, '_SYS_AFL', 'CREATE_TABLE_TYPES', 'INOUT');
entity Expenses {
key id : Integer;
key tripid : Integer;
expenseType : sString;
amount : BinaryFloat;
currency : tString;
trip : Association to Trip on trip.id = tripid;
};
define view ExpensesView as SELECT from Expenses{
Expenses.id as ExpenseId,
trip.id as TripId,
trip.toDate as tripDate,
trip.traveller as employee,
trip.approver_uname as approver,
trip.destination as destination,
Expenses.expenseType as eType,
Expenses.amount as amount
};
entity periodConversion {
key periodId : String(2);
month : String(2);
year : String(4);
}
};
schema="GOOGLE";
query = "SELECT TO_INT(TIMES.\"MONTH_INT\") as \"TIMESTAMP\", SUM(\"amount\") as \"VALUE\" from \"GoogleSheets::Trips.ExpensesView\" as EXPENSES join \"_SYS_BI\".\"M_TIME_DIMENSION\" as TIMES on EXPENSES.\"tripDate\" = TIMES.\"DATE_SQL\" group by TIMES.\"MONTH_INT\" order by \"TIMESTAMP\"; ";
depends_on_table=["HANAGoogleSheets::Trips.ExpensesView"];
/*PAL Selection, training and forecast*/
set schema "GOOGLE";
DROP TYPE PAL_FORECASTMODELSELECTION_DATA_T;
CREATE TYPE PAL_FORECASTMODELSELECTION_DATA_T AS TABLE ("TIMESTAMP" INT, "VALUE" DOUBLE);
DROP TYPE PAL_CONTROL_T;
CREATE TYPE PAL_CONTROL_T AS TABLE ("NAME" VARCHAR(100), "INTARGS" INT, "DOUBLEARGS" DOUBLE, "STRINGARGS" VARCHAR(100));
DROP TYPE PAL_OUTPARAMETER_T;
CREATE TYPE PAL_OUTPARAMETER_T AS TABLE ("NAME" VARCHAR(100), "VALUE" VARCHAR(100));
DROP TYPE PAL_FORECASTMODELSELECTION_FORECAST_T;
CREATE TYPE PAL_FORECASTMODELSELECTION_FORECAST_T AS TABLE ("TIMESTAMP" INT, "VALUE" DOUBLE, "DIFFERENCE" DOUBLE);
/*Signature table
1st position: Input table type
2nd position: Control table
3rd position: Output Parameter table type
4th position: Results*/
DROP TABLE PAL_FORECASTMODELSELECTION_PDATA_TBL;
CREATE COLUMN TABLE PAL_FORECASTMODELSELECTION_PDATA_TBL("POSITION" INT, "SCHEMA_NAME" NVARCHAR(256), "TYPE_NAME" NVARCHAR(256), "PARAMETER_TYPE" VARCHAR(7));
INSERT INTO PAL_FORECASTMODELSELECTION_PDATA_TBL VALUES (1,'GOOGLE', 'PAL_FORECASTMODELSELECTION_DATA_T','IN');
INSERT INTO PAL_FORECASTMODELSELECTION_PDATA_TBL VALUES(2,'GOOGLE', 'PAL_CONTROL_T','IN');
INSERT INTO PAL_FORECASTMODELSELECTION_PDATA_TBL VALUES(3,'GOOGLE', 'PAL_OUTPARAMETER_T','OUT');
INSERT INTO PAL_FORECASTMODELSELECTION_PDATA_TBL VALUES(4,'GOOGLE', 'PAL_FORECASTMODELSELECTION_FORECAST_T','OUT');
/* Call the wrapper procedure to generate the predictive procedure, named "PALFORECASTSMOOTHING_PROC" in this example
CALL SYS.AFLLANG_WRAPPER_PROCEDURE_CREATE (‘<area_name>’, ‘<function_name>’, ‘<schema_name>’, '<procedure_name>', <signature_table>);
<area_name>: Always set to AFLPAL.
<function_name>: A PAL built-in function name.
<schema_name>: A name of the schema that you want to create.
<procedure_name>: A name for the PAL procedure. This can be anything you want.
<signature_table>: A user-defined table variable. The table contains records to describe the position, schema name, table type name, and parameter type, as defined below:
*/
CALL SYS.AFLLANG_WRAPPER_PROCEDURE_DROP('GOOGLE', 'PALFORECASTSMOOTHING_PROC');
CALL SYS.AFLLANG_WRAPPER_PROCEDURE_CREATE('AFLPAL', 'FORECASTSMOOTHING', 'GOOGLE', 'PALFORECASTSMOOTHING_PROC',PAL_FORECASTMODELSELECTION_PDATA_TBL);
/*Create the temporary Control table
Each row contains only one parameter value, either integer, double or string.
This configuration tells the wrapper that we will be training the model based on 90% of the data and that we want the forecast to start after the seventh period
*/
DROP TABLE #PAL_CONTROL_TBL;
CREATE LOCAL TEMPORARY COLUMN TABLE #PAL_CONTROL_TBL ("NAME" VARCHAR(100), "INTARGS" INT, "DOUBLEARGS" DOUBLE,"STRINGARGS" VARCHAR(100));
INSERT INTO #PAL_CONTROL_TBL VALUES ('FORECAST_MODEL_NAME', NULL, NULL,'TESM');
INSERT INTO #PAL_CONTROL_TBL VALUES ('THREAD_NUMBER',8, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('ALPHA', NULL,0.4, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('BETA', NULL,0.4, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('GAMMA', NULL,0.4, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('CYCLE',2, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('FORECAST_NUM',3, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('SEASONAL',0, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('INITIAL_METHOD',1, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('MAX_ITERATION',300, NULL, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('TRAINING_RATIO',NULL, 0.90, NULL);
INSERT INTO #PAL_CONTROL_TBL VALUES ('STARTTIME',7,NULL, NULL);
DROP TABLE PAL_OUTPARAMETER_TBL;
CREATE COLUMN TABLE PAL_OUTPARAMETER_TBL LIKE PAL_OUTPARAMETER_T;
DROP TABLE PAL_FORECASTMODELSELECTION_RESULT_TBL;
CREATE COLUMN TABLE PAL_FORECASTMODELSELECTION_RESULT_TBL LIKE PAL_FORECASTMODELSELECTION_FORECAST_T;
CALL GOOGLE.PALFORECASTSMOOTHING_PROC( "GOOGLE"."HANAGoogleSheets::EXPENSES_SORTED", "#PAL_CONTROL_TBL", PAL_OUTPARAMETER_TBL, PAL_FORECASTMODELSELECTION_RESULT_TBL) WITH OVERVIEW;
SELECT * FROM PAL_OUTPARAMETER_TBL;
SELECT * FROM PAL_FORECASTMODELSELECTION_RESULT_TBL;
"anonymous_connection" : "<<YourRootPackage>>::anonymous",
"exposed" : true,
"authentication" : null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
26 | |
16 | |
14 | |
13 | |
12 | |
9 | |
7 | |
6 | |
6 | |
5 |