Skip to content

Commit 2ca1b4d

Browse files
author
i317814
committed
samples & runtimes for apl 4.2307.0
1 parent 8f6814f commit 2ca1b4d

14 files changed

+90
-56
lines changed

dataForHANACloud.tar.gz

-6 Bytes
Binary file not shown.

runtimes/cpp/DateUtilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool hasFiveWeeks(int iYear, int iMonth)
125125
return true;
126126
else if ((30 == lNbDays) && ((2 == lFirstDay) || (3 == lFirstDay)))
127127
return true;
128-
else if ((29 == lNbDays) && (3 == lNbDays))
128+
else if ((29 == lNbDays) && (3 == lFirstDay))
129129
return true;
130130
else
131131
return false;

runtimes/java/KxJRT.jar

-194 Bytes
Binary file not shown.

runtimes/java/src/DateUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static int ymdToScalar(int iYear, int iMonth, int iDay) {
8181
lScalar += (iYear * 365 + iYear / 4 - iYear / 100 + iYear / 400);
8282
return lScalar;
8383
}
84-
public static int getDayInMonth(Date iDate) {
84+
public static int getDaysInMonth(Date iDate) {
8585
Calendar lCalendar = Calendar.getInstance();
8686
lCalendar.setTime(iDate);
8787
int lMonthDay = 31;
@@ -159,14 +159,14 @@ else if (lCalendar.get(Calendar.MONTH) == Calendar.DECEMBER) {
159159
}
160160

161161
public static boolean hasFiveWeeks(Date iDate) {
162-
int lMonthDay = getDayInMonth(iDate);
162+
int lNbDays = getDaysInMonth(iDate);
163163
int lFirstDay = getDayOfWeek(iDate);
164164

165-
if ((31 == lMonthDay) && (lFirstDay >= 1) && (lFirstDay <=3))
165+
if ((31 == lNbDays) && (lFirstDay >= 1) && (lFirstDay <=3))
166166
return true;
167-
else if ((30 == lMonthDay) && ((2 == lFirstDay) || (3 == lFirstDay)))
167+
else if ((30 == lNbDays) && ((2 == lFirstDay) || (3 == lFirstDay)))
168168
return true;
169-
else if ((29 == lMonthDay) && (3 == lMonthDay))
169+
else if ((29 == lNbDays) && (3 == lFirstDay))
170170
return true;
171171
else
172172
return false;
@@ -209,7 +209,7 @@ public static int getWeekOfMonth(Date iDate) {
209209
lWMonth1 = 4 + (l5Weeks ? 1 : 0);
210210
}
211211

212-
int lNbDaysInMonth = getDayInMonth(iDate);
212+
int lNbDaysInMonth = getDaysInMonth(iDate);
213213

214214
Calendar lNewDate = Calendar.getInstance();
215215
lNewDate.set(lCalendar.get(Calendar.YEAR),

runtimes/java/src/IKxJModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package KxJRT;
1212

1313
/**
14-
* The <a href="http://www.kxen.com">Automatic Analytics</a> Java model interface.
14+
* The Automatic Analytics Java model interface.
1515
* Generated Java code for K2R and K2S implements this interface.
1616
* @version 1.0
1717
*/

runtimes/java/src/KxFileReader.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ public boolean hasMoreLines() {
146146
while (lCurrentLine.equals("")) {
147147
try {
148148
lCurrentLine = mBuffer.readLine();
149+
if (lCurrentLine == null) {
150+
return false;
151+
}
149152
}
150153
catch ( IOException e ) {
151154
return false;
@@ -174,30 +177,6 @@ private void initFields( String iLine ) {
174177
mFields = new String[lFieldsCount];
175178
}
176179

177-
private void printLineError() {
178-
KxLog.getInstance().print("More fields are found\n");
179-
System.err.println( "error : found more fields than exprected line "+
180-
mRowCounter +".");
181-
}
182-
183-
private void printFieldError( int iFieldIndex ) {
184-
KxLog.getInstance().print( "warning : invalid type for field "+
185-
iFieldIndex+ " line " + mRowCounter + "." );
186-
}
187-
188-
private void printEmptyField( int iFieldIndex ) {
189-
if (null != mNameFields) {
190-
KxLog.getInstance().print( "warning : empty value for " +
191-
mNameFields[iFieldIndex] +" at line " +
192-
mRowCounter + "." );
193-
}
194-
else {
195-
KxLog.getInstance().print( "warning : empty value for fields " +
196-
iFieldIndex +" at line " +
197-
mRowCounter + "." );
198-
}
199-
}
200-
201180
public boolean isEmpty( int iVariableIndex, String iMissingString ) {
202181
String lValue = mFields[ iVariableIndex ];
203182
if( lValue == null

runtimes/java/src/KxFileReaderWithNames.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void init() {
5858
}
5959
}
6060

61-
public String[] getVariables() {
61+
final public String[] getVariables() {
6262
return mVariables;
6363
}
6464

runtimes/java/src/KxInputReader.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ public void initFields( String iLine ) {
5959
}
6060
}
6161

62-
private void printLineError() {
63-
KxLog.getInstance().print("More fields are found\n");
64-
System.err.println( "error : found more fields than exprected line "+
65-
mRowCounter +".");
66-
}
67-
68-
private void printFieldError( int iFieldIndex ) {
69-
KxLog.getInstance().print( "warning : invalid type for field "+
70-
iFieldIndex+ " line " + mRowCounter + "." );
71-
}
72-
7362
private void printEmptyField( int iFieldIndex ) {
7463
KxLog.getInstance().print("warning : empty value for fields " +
7564
iFieldIndex +" at line " +

runtimes/java/src/KxJApplyOnFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.lang.*;
1515

1616
/**
17-
* Applies a <a href="http://www.kxen.com">Automatic Analytics</a> Java model on a flat file
17+
* Applies a Automatic Analytics Java model on a flat file
1818
* with variable names on the first line.
1919
* @see KxJRT.KxFileReaderWithNames KxFileReaderWithNames
2020
* @see KxJRT.KxFileReader KxFileReader

runtimes/java/src/KxJApplyOnInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.TreeMap;
1616

1717
/**
18-
* Applies a <a href="http://www.kxen.com">Automatic Analytics</a> Java model on a line
18+
* Applies a Automatic Analytics Java model on a line
1919
* @see KxJRT.KxInputReader KxInputReader
2020
*/
2121
public class KxJApplyOnInput {

runtimes/java/src/KxJApplyOnJDBC.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ else if( iArgs[i].equalsIgnoreCase("-usage") ||
176176
lApplyScore = new KxJApplyOnJDBC(lModel);
177177

178178
loadDriver(lDriver);
179-
180-
Connection lConnection = newConnection(lDatabase, lUser, lPwd);
181-
Statement lStatement = lConnection.createStatement();
182179

183-
ResultSet lResult = lStatement.executeQuery(lQuery);
180+
try(Connection lConnection = newConnection(lDatabase, lUser, lPwd);
181+
Statement lStatement = lConnection.createStatement())
182+
{
184183

185-
lApplyScore.apply(lResult, lOut);
184+
ResultSet lResult = lStatement.executeQuery(lQuery);
185+
186+
lApplyScore.apply(lResult, lOut);
187+
}
186188

187189
} catch(Exception e )
188190
{

runtimes/java/src/KxJApplyWithMapWrapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import java.text.ParseException;
88

99
public class KxJApplyWithMapWrapper {
10-
public static String mDesc = "Automatic Analytics command line score calculator.\n Expected input:\n \n KxJApplyWithMapWrapper ScorerClass var1=value1 var2=value2 ...\n \n where \"ScorerClass\" is the name of the class generated by Automatic Analytics (which should\n be in the classpath)";
11-
1210
public String mScorerClassName;
1311
private IKxJModel mScorerModel;
1412

@@ -120,7 +118,11 @@ else if( iArgs[i].equalsIgnoreCase("-usage") ) {
120118
BufferedReader lBuffer = new BufferedReader(lStreamReader);
121119

122120
// skip the first row which contains the header file
123-
String lCurrentLine = lBuffer.readLine();
121+
String lCurrentLine = lBuffer.readLine();
122+
if (lCurrentLine == null) {
123+
System.out.println("Empty input file.");
124+
return;
125+
}
124126
String[] lVariables = lCurrentLine.split(lSeparator);
125127

126128
for (String lOutput:lMapWrapper.mScorerModel.getModelOutputVariables())

runtimes/java/src/KxJDBCInput.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public float floatValue( int iIndex ) {
9999
mMissing = false;
100100
}
101101
catch( SQLException e ) {
102-
lValue = (float)0.0;
103102
mMissing = true;
104103
}
105104
return lValue;
@@ -112,7 +111,6 @@ public double doubleValue( int iIndex ) {
112111
mMissing = false;
113112
}
114113
catch( SQLException e ) {
115-
lValue = 0.0;
116114
mMissing = true;
117115
}
118116
return lValue;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- @required(hanaMinimumVersion,4.00.000)
2+
-- ================================================================
3+
-- APL_AREA, APPLY_MODEL, using a binary format for the model
4+
-- This script demonstrates the application of the binary classification model
5+
-- to predict the target and to get the individual contributions per input
6+
--
7+
-- Assumption 1: The users & privileges have been created & granted (see apl_admin_ex.sql).
8+
-- Assumption 2: There's a valid trained model (created by APL) in the MODEL_TRAIN_BIN table.
9+
-- @depend(segmented_create_train_hce.sql)
10+
connect USER_APL password Password1;
11+
SET SESSION 'APL_CACHE_SCHEMA' = 'APL_CACHE';
12+
13+
drop table APPLY_OPERATION_LOG;
14+
create table APPLY_OPERATION_LOG like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
15+
16+
drop table APPLY_SUMMARY;
17+
create table APPLY_SUMMARY like "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
18+
19+
-- USER_APL.APPLY_OUT definition
20+
DROP TYPE APPLY_OUT_T;
21+
CREATE TYPE APPLY_OUT_T AS TABLE ("KxIndex" BIGINT,"class" INTEGER,"gb_score_class" DOUBLE, "Seg" INTEGER);
22+
23+
DROP TABLE APPLY_OUT;
24+
CREATE TABLE APPLY_OUT LIKE APPLY_OUT_T;
25+
26+
27+
DO BEGIN
28+
declare header "SAP_PA_APL"."sap.pa.apl.base::BASE.T.FUNCTION_HEADER";
29+
declare config "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_CONFIG_EXTENDED";
30+
declare model "SAP_PA_APL"."sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
31+
declare out_log "SAP_PA_APL"."sap.pa.apl.base::BASE.T.OPERATION_LOG";
32+
declare out_sum "SAP_PA_APL"."sap.pa.apl.base::BASE.T.SUMMARY";
33+
declare apply_out APPLY_OUT_T;
34+
35+
insert into :model select * from MODEL_TRAIN_BIN;
36+
datatset = SELECT * from "USER_APL"."ADULT01_SORTED";
37+
38+
:header.insert(('Oid', '#42'));
39+
:header.insert(('LogLevel', '2'));
40+
:header.insert(('ModelFormat', 'bin'));
41+
:header.insert(('MaxTasks', '2')); -- define nb parallel tasks to use for train
42+
43+
:config.insert(('APL/SegmentColumnName', 'Seg',null)); -- define the column used as the segmentation colum
44+
45+
CALL _SYS_AFL.APL_APPLY_MODEL__OVERLOAD_4_3(:header, :model, :config, :datatset,apply_out,out_log,out_sum);
46+
47+
insert into APPLY_OUT select * from :apply_out;
48+
insert into APPLY_OPERATION_LOG select * from :out_log;
49+
insert into APPLY_SUMMARY select * from :out_sum;
50+
END;
51+
52+
SELECT "Seg", count(*) from APPLY_OUT group by "Seg";
53+
54+
-- Nb trained models
55+
select count(*) from APPLY_SUMMARY where "KEY" = 'AplTaskElapsedTime';
56+
57+
-- Average time to train a segment
58+
select AVG(to_double("VALUE")) from APPLY_SUMMARY where "KEY" = 'AplTaskElapsedTime';
59+
60+
-- Total time
61+
select * from APPLY_SUMMARY where "KEY" = 'AplTotalElapsedTime';
62+
63+
-- Get models in error
64+
select * from APPLY_OPERATION_LOG where "LEVEL" = 0;

0 commit comments

Comments
 (0)