Skip to content

Commit

Permalink
samples & runtimes for apl 4.2309.0
Browse files Browse the repository at this point in the history
  • Loading branch information
i317814 committed Mar 28, 2023
1 parent 2ca1b4d commit 6c5f351
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 23 deletions.
Binary file modified dataForHANACloud.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion runtimes/cpp/Sample/linux.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright....: (c) SAP 1999-2021
# Copyright....: (c) SAP 1999-2023
# Project......:
# Library......:
# File.........: linux.mak
Expand Down
2 changes: 1 addition & 1 deletion runtimes/cpp/Sample/win.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright....: (c) SAP 1999-2021
# Copyright....: (c) SAP 1999-2023
# Project......:
# Library......:
# File.........: win.mak
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# ----------------------------------------------------------------------------
# Copyright....: (c) SAP 1999-2021
# Project......:
# Library......:
# File.........: win.mak
# Author.......:
# Created......: Tue Mar 09 16:51:38 2010
# Description..:
#
# CVS infos....:
# .............. $Id: win_X64-WIN64.mak,v 1.2 2012/05/30 10:28:17 port Exp $
# .............. $Date: 2012/05/30 10:28:17 $
# .............. $Revision: 1.2 $
# ----------------------------------------------------------------------------

# Some macros for SUN OS compiler
# ----------------------------------------------------------------------------
# Copyright....: (c) SAP 1999-2023
# Project......:
# Library......:
# File.........: win.mak
# Author.......:
# Created......: Tue Mar 09 16:51:38 2010
# Description..:
#
# CVS infos....:
# .............. $Id: win_X64-WIN64.mak,v 1.2 2012/05/30 10:28:17 port Exp $
# .............. $Date: 2012/05/30 10:28:17 $
# .............. $Revision: 1.2 $
# ----------------------------------------------------------------------------

# Some macros for SUN OS compiler
include win_X64-WIN64.mak
2 changes: 1 addition & 1 deletion runtimes/cpp/Sample/win_X64-WIN64.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ----------------------------------------------------------------------------
# Copyright....: (c) SAP 1999-2021
# Copyright....: (c) SAP 1999-2023
# Project......:
# Library......:
# File.........: win.mak
Expand Down
Binary file modified runtimes/java/KxJRT.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions sql/check_apl/check_apl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1346,15 +1346,15 @@ BEGIN
:final_results.insert(('==============================','',''));
END IF;
-- keep using LOWER. This is not a mistake
SELECT LOWER(SESSION_USER) into who_am_i FROM "DUMMY";
SELECT SUBSTR(LOWER(SESSION_USER),0,9) into who_am_i FROM "DUMMY";
IF :who_am_i <> 'check_apl' AND :who_am_i<>'rouser'
THEN
-- do the final check and pop an sql error
-- if an issue is detected
SELECT COUNT(*) into nb_issues FROM :final_results WHERE "STATUS" IN ('ISSUE','ERROR');
IF :nb_issues > 0
THEN
SELECT '['||STRING_AGG("KEY" || ' ' || COALESCE("STATUS",'') || ' ' || COALESCE("DETAILS",'') || CHAR(10))||']' INTO error_message FROM :final_results;
SELECT SUBSTR('['||STRING_AGG("KEY" || ' ' || COALESCE("STATUS",'') || ' ' || COALESCE("DETAILS",'') || CHAR(10))||']',0,3000) INTO error_message FROM :final_results;
SIGNAL ERROR_APL set MESSAGE_TEXT = :error_message;
END IF;
END IF;
Expand Down
4 changes: 2 additions & 2 deletions sql/check_apl/check_apl_without_creating_check_apl_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1279,15 +1279,15 @@ BEGIN
:final_results.insert(('==============================','',''));
END IF;
-- keep using LOWER. This is not a mistake
SELECT LOWER(SESSION_USER) into who_am_i FROM "DUMMY";
SELECT SUBSTR(LOWER(SESSION_USER),0,9) into who_am_i FROM "DUMMY";
IF :who_am_i <> 'check_apl' AND :who_am_i<>'rouser'
THEN
-- do the final check and pop an sql error
-- if an issue is detected
SELECT COUNT(*) into nb_issues FROM :final_results WHERE "STATUS" IN ('ISSUE','ERROR');
IF :nb_issues > 0
THEN
SELECT '['||STRING_AGG("KEY" || ' ' || COALESCE("STATUS",'') || ' ' || COALESCE("DETAILS",'') || CHAR(10))||']' INTO error_message FROM :final_results;
SELECT SUBSTR('['||STRING_AGG("KEY" || ' ' || COALESCE("STATUS",'') || ' ' || COALESCE("DETAILS",'') || CHAR(10))||']',0,3000) INTO error_message FROM :final_results;
SIGNAL ERROR_APL set MESSAGE_TEXT = :error_message;
END IF;
END IF;
Expand Down
25 changes: 25 additions & 0 deletions sql/procedure/apl_samples/timeseries/apl_apply_proc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ BEGIN
"SAP_PA_APL"."sap.pa.apl.base::CREATE_TABLE_FROM_TABLE_TYPE"(:apply_out_schema, :apply_out_table, :out_schema);
"SAP_PA_APL"."sap.pa.apl.base::APPLY_MODEL"(:header, :model, :config, :apply_in_schema, :apply_in_table, :apply_out_schema, :apply_out_table , out_apply_log, out_apply_sum);
END;



drop PROCEDURE "apl_apply_debrief_example";
CREATE PROCEDURE "apl_apply_debrief_example" (
IN header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER",
IN model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID",
IN config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED",
IN apply_in_schema VARCHAR (127),
IN apply_in_table VARCHAR (127),
IN apply_out_schema VARCHAR (127),
IN apply_out_table VARCHAR (127),
OUT out_apply_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG",
OUT out_apply_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY",
OUT out_debrief_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID",
OUT out_debrief_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID"
)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
BEGIN
"SAP_PA_APL"."sap.pa.apl.base::GET_TABLE_TYPE_FOR_APPLY"(:header, :model, :config, :apply_in_schema, :apply_in_table,out_schema, out_log);
"drop_table_if_exit"(:apply_out_schema, :apply_out_table);
"SAP_PA_APL"."sap.pa.apl.base::CREATE_TABLE_FROM_TABLE_TYPE"(:apply_out_schema, :apply_out_table, :out_schema);
"SAP_PA_APL"."sap.pa.apl.base::APPLY_MODEL_DEBRIEF"(:header, :model, :config, :apply_in_schema, :apply_in_table, :apply_out_schema, :apply_out_table , out_apply_log, out_apply_sum,out_debrief_metric,out_debrief_property);
END;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
-- @required(hanaMinimumVersion,2.0.40)
-- ================================================================
-- APL_AREA, FORECAST
-- Description :
-- Assumption 1: the users & privileges have been created & granted (see apl_admin_ex.sql).
-- @depend(apl_apply_proc.sql)

connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';


-- --------------------------------------------------------------------------
-- Create a view which contains the sorted dataset
-- --------------------------------------------------------------------------

drop view CASHFLOWS_SORTED;
create view CASHFLOWS_SORTED as select * from APL_SAMPLES.CASHFLOWS_FULL order by "Date" asc;

-- --------------------------------------------------------------------------
-- Create the input/output tables used as arguments for the APL function
-- --------------------------------------------------------------------------
drop table MODEL_BIN_OUT;
create table MODEL_BIN_OUT like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";

drop table OPERATION_LOG;
create table OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

drop table SUMMARY;
create table SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";

drop table INDICATORS;
create table INDICATORS like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.INDICATORS";

drop table APPLY_LOG;
create column table APPLY_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

drop table APPLY_SUMMARY;
create column table APPLY_SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";

drop table APPLY_DEBRIEF_METRIC;
create table APPLY_DEBRIEF_METRIC like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";

drop table APPLY_DEBRIEF_PROPERTY;
create table APPLY_DEBRIEF_PROPERTY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";

drop table APPLY_OUT;

DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare apply_config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare var_desc "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_DESC_OID";
declare var_role "SAP_PA_APL"."sap.pa.apl.base::BASE.T.VARIABLE_ROLES_WITH_COMPOSITES_OID";

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '8'));
:header.insert(('ModelFormat', 'bin'));

:config.insert(('APL/ModelType', 'timeseries',null));
:config.insert(('APL/Horizon', '20',null));
:config.insert(('APL/TimePointColumnName', 'Date',null));
:config.insert(('APL/LastTrainingTimePoint', '2001-12-29 00:00:00',null));
:config.insert(('APL/WithExtraPredictable', 'false',null));
:config.insert(('APL/ForcePositiveForecast', 'true',null));

:var_role.insert(('Date', 'input',null,null,null));
:var_role.insert(('Cash', 'target',null,null,null));

insert into :var_desc select *,'42' from APL_SAMPLES.CASHFLOWS_DESC;

"SAP_PA_APL"."sap.pa.apl.base::CREATE_MODEL_AND_TRAIN"(:header, :config, :var_desc,:var_role, 'USER_APL','CASHFLOWS_SORTED', model, train_log, train_sum, train_indic);

call "apl_apply_debrief_example"(:header, :model, :config, 'USER_APL','CASHFLOWS_SORTED', 'USER_APL','APPLY_OUT',out_apply_log,out_apply_sum,out_debrief_metric, out_debrief_property);

-- store result into table
insert into "USER_APL"."MODEL_BIN_OUT" select * from :model;
insert into "USER_APL"."OPERATION_LOG" select * from :train_log;
insert into "USER_APL"."SUMMARY" select * from :train_sum;
insert into "USER_APL"."INDICATORS" select * from :train_indic;
insert into "USER_APL"."APPLY_LOG" select * from :out_apply_log;
insert into "USER_APL"."APPLY_SUMMARY" select * from :out_apply_sum;
insert into "USER_APL"."APPLY_DEBRIEF_PROPERTY" select * from :out_debrief_property;
insert into "USER_APL"."APPLY_DEBRIEF_METRIC" select * from :out_debrief_metric;
END;

select * from "USER_APL"."APPLY_OUT";
select * from "USER_APL"."APPLY_DEBRIEF_PROPERTY";
select * from "USER_APL"."APPLY_DEBRIEF_METRIC";
67 changes: 67 additions & 0 deletions sql/procedure/apl_samples/timeseries/segmented_apply_debrief.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-- @required(hanaMinimumVersion,2.0.40)
-- ================================================================
-- APL_AREA, APPLY_MODEL, using a binary format for the model
-- This script demonstrates the application of the binary classification model
-- to predict the target and to get the individual contributions per input
--
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql).
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table.
-- @depend(segmented_create_train.sql)
-- @depend(apl_apply_proc.sql)
connect USER_APL password Password1;
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';

drop table APPLY_OPERATION_LOG;
create table APPLY_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";

drop table APPLY_SUMMARY;
create table APPLY_SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";

drop table APPLY_DEBRIEF_METRIC;
create table APPLY_DEBRIEF_METRIC like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";

drop table APPLY_DEBRIEF_PROPERTY;
create table APPLY_DEBRIEF_PROPERTY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";


DO BEGIN
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
declare out_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
declare out_debrief_metric "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_METRIC_OID";
declare out_debrief_property "SAP_PA_APL"."sap.pa.apl.base::BASE.T.DEBRIEF_PROPERTY_OID";

insert into :model select * from MODEL_TRAIN_BIN;

:header.insert(('Oid', '#42'));
:header.insert(('LogLevel', '8'));
:header.insert(('ModelFormat', 'bin'));
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train

:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
:config.insert(('APL/ApplyLastTimePoint', '2001-12-29 00:00:00',null));

call "apl_apply_debrief_example"(:header, :model, :config, 'USER_APL','CASHFLOWS_SORTED', 'USER_APL','APPLY_OUT',out_log,out_sum,out_debrief_metric, out_debrief_property);

insert into APPLY_OPERATION_LOG select * from :out_log;
insert into APPLY_SUMMARY select * from :out_sum;
insert into APPLY_DEBRIEF_PROPERTY select * from :out_debrief_property;
insert into APPLY_DEBRIEF_METRIC select * from :out_debrief_metric;
END;

--SELECT * from CASHFLOWS_SORTED;
SELECT "Seg", count(*) from APPLY_OUT group by "Seg";

-- Nb trained models
select count(*) from APPLY_SUMMARY where "KEY" = 'AplTaskElapsedTime';

-- Average time to train a segment
select AVG(to_double("VALUE")) from APPLY_SUMMARY where "KEY" = 'AplTaskElapsedTime';

-- Total time
select * from APPLY_SUMMARY where "KEY" = 'AplTotalElapsedTime';

-- Get models in error
select * from APPLY_OPERATION_LOG where "LEVEL" = 0;

0 comments on commit 6c5f351

Please sign in to comment.