PUBLIC SAP Data Hub 2.5 Document Version: 2.5.0 – 2019-04-19

SQL Reference for SAP Vora in SAP Data Hub company. All rights reserved. affiliate

THE BEST RUN 2019 SAP SE or an SAP © Content

1 SQL Reference for SAP Vora in SAP Data Hub...... 4 1.1 Notation...... 4 1.2 Introduction to SQL...... 5 1.3 Data Types...... 7 Classification of Data Types...... 7 Boolean Data Type...... 7 Character String Data Types...... 8 Date/Time Types...... 10 Numeric Types...... 11 Constant Literals...... 14 Data Type Conversion...... 15 1.4 SQL Statements...... 16 Access Control (DDL)...... 26 Data Manipulation Language (DML)...... 36 (DDL)...... 48 Data (DQL)...... 83 1.5 SQL Functions and Operators ...... 88 Numeric Functions...... 98 String Functions...... 99 Datetime Functions...... 100 Data Type Conversion Functions...... 102 Hierarchy Functions...... 105 Miscellaneous Functions...... 106 Table-Valued Functions...... 108 Partitioning Tables...... 109 1.6 System Views...... 112 SYS.TABLES...... 115 SYS.SCHEMAS...... 116 SYS.TABLE_COLUMNS...... 116 SYS.VIEWS...... 117 SYS.CONSTRAINTS...... 117 SYS.MATERIALIZED_VIEWS...... 118 SYS.MATERIALIZED_VIEW_COLUMNS...... 118 SYS.SYNONYMS...... 119 SYS.DUMMY...... 120 SYS.VORA_DATABASE...... 120

SQL Reference for SAP Vora in SAP Data Hub 2 PUBLIC Content SYS.M_DATABASE...... 120 SYS.VORA_CAPABILITIES...... 121 SYS.VORA_FUNCTIONS...... 121 SYS.VORA_TABLES...... 122 SYS.VORA_TABLE_COLUMNS...... 122 SYS.VORA_DATASOURCES...... 123 SYS.VORA_PARTITION_SCHEMES...... 124 SYS.VORA_PARTITION_FUNCTIONS...... 124 SYS.VORA_PARTITION_PARAMETERS...... 125 SYS.VORA_PARTITION_DEFINITIONS...... 125 SYS.OBJECTS...... 126 SYS.OBJECT_VERSIONS...... 126 SYS.OBJECT_DEPENDENCIES...... 127 SYS.ROLES...... 128 SYS.USERS...... 128 SYS.GRANTED_ROLES...... 129 SYS.GRANTED_PRIVILEGES...... 129 SYS.AUDIT_POLICIES...... 130 SYS.VORA_STATISTICS...... 131 SYS.VORA_SERIES_TABLES...... 131 SYS.SERIES_KEY_COLUMNS...... 132 SYS.VORA_DATASOURCE_FILES...... 132 1.7 SAP VORA Configuration Framework...... 133 Alter System...... 133

SQL Reference for SAP Vora in SAP Data Hub Content PUBLIC 3 1 SQL Reference for SAP Vora in SAP Data Hub

The SAP Vora SQL Reference describes all SQL data types, predicates, operators, expressions, functions, statements, error codes, and system views.

SAP Vora SQL is aligned with the SQL used by SAP HANA, so the SAP HANA SQL Reference is an additional valuable source of information. In general, SAP Vora SQL is a subset of SAP HANA SQL - the cases where Vora SQL differs from HANA SQL are pointed out explicitly. Also note that the public interface is aligned with the SQL 2011 standard.

Related Information

Notation [page 4] Introduction to SQL [page 5] Data Types [page 7] SQL Statements [page 16] SQL Functions and Operators [page 88] System Views [page 112] SAP VORA Configuration Framework [page 133]

1.1 Notation

This reference uses EBNF (extended Backus-Naur form), a notation technique used to define programming languages. EBNF describes the syntax of a grammar using a set of production rules and a set of symbols.

The following items are used in this guide:

Symbol Meaning

::= Definition, left side is defined by right side

| OR operator

( ... ) Grouped tokens

{ ... } Zero or more repetitions

[ ... ] Zero or one repetition

'...' Literal final token

 Note

All uppercase strings are used as final literal tokens. All lowercase strings are non-terminal symbols.

SQL Reference for SAP Vora in SAP Data Hub 4 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.2 Introduction to SQL

This section describes the SAP Vora implementation of Structured Query Language (SQL).

Supported Languages and Code Pages

The SAP Vora database supports Unicode to allow the use of all languages in the Unicode Standard and 7 Bit ASCII code page without restriction.

Comments

You can add comments to improve the readability and maintainability of your SQL statements. Comments are delimited in SQL statements as follows:

● Double hyphens "--". Everything after the double hyphen until the end of a line is ignored by the SQL parser. ● "/*" and "*/". This style of commenting is used to place comments on multiple lines. All text between the opening "/*" and closing "*/" is ignored by the SQL parser.

Example of using comments:

-- creating a schema:

CREATE SCHEMA s; /* let's set this schema to use it: */

SET SCHEMA s;

Identifiers

Identifiers are used to represent names used in SQL statement including table name, view name, synonym name, column name, index name, function name, procedure name, user name, role name, and so on. There are two kinds of identifiers, undelimited identifiers and delimited identifiers:

● Undelimited identifiers must start with a letter and cannot contain any symbols other than digits or an underscore "_". ● Delimited identifiers are enclosed in the delimiter, double quotes. The identifier can then contain any character including special characters. "AB$%CD" is a valid identifier name for example. ● Limitations: ○ Undelimited identifiers must not be equal to any reserved keywords. Using delimiters is a safe way to avoid conflicts with reserved keywords. ○ There is a set of identifiers which are used for the database engine and therefore cannot be used in specific contexts. See System Views [page 112].

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 5 Example of using delimited and undelimited identifiers:

CREATE TABLE t("1+1" INT) TYPE DATASOURCE;

SELECT "1+1" FROM t;

Identifiers and Case Sensitivity

Identifiers without double-quotes in SQL syntax are converted to upper case when processed by the server. For example, the statement CREATE COLUMN TABLE MyTAB... creates a table called MYTAB, whereas CREATE COLUMN TABLE "MyTab" creates a table called MyTab - and both tables can co-exist in the database.

 Sample Code

-- both these statements will succeed:

CREATE TABLE MyTable(i INT) TYPE DATASOURCE;

CREATE TABLE "MyTable"(i INT) TYPE DATASOURCE;

Specifying identifiers without double-quotes is allowed but can cause ambiguity later when querying or performing operations on objects where casing in the identifier name is significant. A recommendation is to standardize to using double-quotes around all identifiers in SQL statements where ambiguity may be a concern.

Quotation Marks

Single quotation marks (') are used to delimit string literals. A single quotation mark itself can be represented using two single quotation marks (''). Double quotation marks are used to delimit identifiers. A double quotation mark itself can be represented using two double quotation marks

The following example:

CREATE TABLE t1(name CHAR(10), "a""strange_name" int) WITH TYPE STREAMING; INSERT INTO t1 VALUES ('Andrew', 1), ('''', 2), ('"', 3);

SELECT * FROM t1; will return:

NAME a"strange_name

Andrew 1

' 2

" 3

SQL Reference for SAP Vora in SAP Data Hub 6 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.3 Data Types

A data type defines the characteristics of a data value. A special value of NULL is included in every data type to indicate the absence of a value.

Related Information

Classification of Data Types [page 7] Boolean Data Type [page 7] Character String Data Types [page 8] Date/Time Types [page 10] Numeric Types [page 11] Constant Literals [page 14] Data Type Conversion [page 15]

1.3.1 Classification of Data Types

In the SAP Vora database, each data type can be classified by its characteristics as shown below.

Classification Data Type

Boolean BOOLEAN

Character CHAR, VARCHAR, NVARCHAR

Other NODE

Datetime DATE, TIME, TIMESTAMP

Numeric TINYINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT, REAL, DOUBLE

1.3.2 Boolean Data Type

The BOOLEAN data type stores boolean values, which are TRUE, FALSE, or NULL.

When the client does not support a boolean type, it returns 1 for TRUE and 0 for FALSE.

The following example returns TRUE or 1 for boolean:

CREATE TABLE TEST (A BOOLEAN) TYPE STREAMING;

INSERT INTO TEST VALUES (TRUE); INSERT INTO TEST VALUES (FALSE);

SELECT A "boolean" FROM TEST WHERE A = TRUE;

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 7 The following select statement is allowed in SAP Vora but not allowed in SAP HANA:

CREATE TABLE DUMMY(A INT, B INT, C INT, D INT) TYPE DATASOURCE;

SELECT * FROM DUMMY WHERE ( A>B ) = ( C>D );

1.3.3 Character String Data Types

Character string data types are used to store values that contain character strings. CHAR data types contain 7- bit ASCII character strings and are used to store fixed-length character strings. VARCHAR and NVARCHAR are synonyms and used for storing Unicode character strings and are equivalent to NVARCHAR in SAP HANA.

Collation expressions are not supported, and values of string data type are compared using a binary comparison based on CESU-8/UTF-16 encoding.

Character string data types in SAP Vora use 7-bit ASCII. Extended ASCII characters are converted into corresponding Unicode characters. If the data includes anything other than 7-bit ASCII characters, use Unicode character string types, such as NVARCHAR.

In SAP Vora, VARCHAR is currently a synonym for NVARCHAR and not a separate data type (SAP HANA limits VARCHAR to 7-bit ASCII, while NVARCHAR allows Unicode).

Table 1: Character String Data Types

Data Type Description

NVARCHAR The NVARCHAR () data type specifies a variable-length character string, where indicates the maximum length in code units and is an integer between 1 and 536870911 (2147483647/4) in SAP Vora files engine and relational in- memory engine. In SAP Vora, NVARCHAR allows Unicode characters.

 Note

SAP HANA restricts to a maximum of 5000. It is therefore strongly recommended to remain within that given range to ensure compatibility.

VARCHAR The VARCHAR () Is a synonym for NVARCHAR. It is strongly recommended to use VARCHAR only for types dedi­ cated to 7-bit ASCII content. SAP HANA limits VARCHAR to 7-bit ASCII, while SAP HANA NVARCHAR also allows Uni­ code.

CHAR The CHAR() data type specifies a fixed-length charac­ ter string, where indicates length in bytes and is an in­ teger between 1 and 5000. Use CHAR with 7-bit ASCII char­ acter-based strings only. For most scenarios, we recom­ mend that VARCHAR is used instead of CHAR if ex­ ceeds 8. The maximum length in the SAP Vora disk engine is 5000.

SQL Reference for SAP Vora in SAP Data Hub 8 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Examples:

CREATE TABLE T2(A NVARCHAR(1), B NVARCHAR(5000), C VARCHAR(1), D VARCHAR(5000), E CHAR(1), F CHAR(5000)) WITH TYPE STREAMING ENGINE 'DISK';

CREATE TABLE T3(A NVARCHAR(1), B NVARCHAR(536870911), C VARCHAR(1), D VARCHAR(536870911), E CHAR(1), F CHAR(255)) WITH TYPE DATASOURCE ENGINE 'MEMORY';

Usage of the CHAR type may offer performance advantages for small length ( < 16 ) data of fixed length with 7-bit-Ascii content. Examples are: Fixed length non-space data, e.g. product numbers ( "3001234", "3004005"), BIC code ( "BNPAIDJA" ).

Use VARCHAR if at least one of the following criteria is met:

● The data is of varying length (e.g. library of congress codes ) leading to trailing spaces in the fields. ● The data contains spaces. ● The length of the field is larger than 15.

 Note

The ABAP CHAR(NU) type is represented as an NVARCHAR within SAP HANA.

Encoding

CHAR uses 7-Bit ASCII with a direct binary representation.

NVARCHAR and VARCHAR as internally stored in an encoding compatible with SAP HANA, ABAP, Microsoft Windows(TM), Java(TM), JavaScript(TM) and other systems using and UTF-16 representation.

Length semantics and sort order are equivalent to the respective behavior of these platforms:

● Unicode codepoints made up of two surrogate pairs count as 2 code units and may be split by substring operations. ● Half-surrogate pairs can be stored ● Characters outside of the BMP (basic multilingual plane) sort between U+D7FF and U+E000 (unlike systems or programming languages which use an UTF-8 or UTF-32 binary sort collation).

The system accepts valid unicode codepoints U+0000 - U+10FFFF. Invalid binary data or codepoints outside this range may be rejected or silently converted into U+FFFD.

 Note

Note that half-surrogate pairs are silently replaced by U+FFFD when accessed by clients (or exported to a file) in an encoding, which does not support their representation (e.g. UTF-8). Use a client encoding, which allows their representation (e.g. UTF-16 Java/JDBC ) to access this data.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 9 1.3.4 Date/Time Types

The following data types are used to store date and time information.

Data Type Description

DATE The DATE data type consists of year, month, and day infor­ mation to represent a date value. The default format for the DATE data type is YYYY-MM-DD. YYYY represents the year, MM represents the month, and DD represents the day. The range of the date value is between 0001-01-01 and 9999-12-31.

TIME The TIME data type consists of hour, minute, second, and fractions of seconds up to 10 ns resolution. The default for­ mat for the TIME data type is HH24:MI:SS.FF. HH24 repre­ sents the hour from 0 to 23, MI represents the minute from 0 to 59, SS represents the second from 0 to 59, and FF rep­ resents the fraction of seconds with up to 7 digits. The SAP Vora disk engine supports fractions of seconds with up to 6 digits and will silently round or truncate, reducing precision.

TIMESTAMP The TIMESTAMP data type consists of date and time infor­ mation. Its default format is YYYY-MM-DD HH24:MI:SS.FF7. FF represents the fractional seconds where indicates the number of digits in the fractional part. The range of the time­ stamp value is between 0001-01-01 00:00:00.0000000 and 9999-12-31 23:59:59.9999999. The SAP Vora disk engine supports fractions of seconds with up to 6 digits and will si­ lently round or truncate, reducing precision.

For the disk engine, the display of TIMESTAMP data outside the range of 1600-02-28 23:59:59 to 7911-01-01 00:00:00 might be incomplete, but the complete timestamp value is stored in the database. You can use the CAST() function to do this, as in the following example, which first creates a table with DATETIME and TIMESTAMP columns and then inserts values where the date is greater 7911-01-01:

Example:

CREATE TABLE MYDATES (ID INT, DESCRIPT CHAR(20), TIMESTAMP_NULL TIMESTAMP) WITH TYPE STREAMING; INSERT INTO MYDATES VALUES (1, 'EXAMPLE', '7911-12-30 06:03:44');

SELECT * FROM MYDATES;

When you select without using CAST, hours and minutes are set to 00:00:

ID DESCRIPT TIMESTAMP_NULL

1 EXAMPLE 7911-12-30 00:00:44.0000000

Another example:

CREATE TABLE T4(D DATE, T TIME, TS TIMESTAMP) WITH TYPE STREAMING; INSERT INTO T4 VALUES ('0001-01-01', '0:0:0.1234567', '0001-01-01 00:00:00.0000000'), ('9999-12-31', '23:59:59.00001', '9999-12-31 23:59:59.9999999');

SELECT * FROM T4;

SQL Reference for SAP Vora in SAP Data Hub 10 PUBLIC SQL Reference for SAP Vora in SAP Data Hub D T TS

0001-01-01 00:00:00.1234560 0001-01-01 00:00:00.0000000

9999-12-31 23:59:59.0000100 9999-12-31 00:00:59.9999990

1.3.5 Numeric Types

The following data types are used to store numeric information.

Table 2: Numeric Types

Data Type Description

TINYINT The TINYINT data type stores an 8-bit unsigned integer. The minimum value is 0. The maximum value is 255.

SMALLINT The SMALLINT data type stores a 16-bit signed integer. The minimum value is -32,768 (-2^15). The maximum value is 32,767 (2^15-1).

INTEGER or INT The INTEGER or INT data type stores a 32-bit signed integer. The minimum value is -2,147,483,648 (-2^31). The maximum value is 2,147,483,647 (2^31-1).

BIGINT The BIGINT data type stores a 64-bit signed integer. The minimum value is -9,223,372,036,854,775,808 (-2^63). The maximum value is 9,223,372,036,854,775,807 (2^63-1).

DECIMAL DECIMAL(p, s) is the SQL standard notation for fixed-point decimal.

specifies precision or the number of total digits (the sum of whole digits and fractional digits). denotes scale or the number of fractional digits. Precision

can range from 1 to 38. The scale can range from 0 to

. If the scale is not specified, it defaults to 0.

REAL The REAL data type specifies a single-precision 32-bit float- ing-point number.

FLOAT The FLOAT() data type specifies a 32-bit or 64-bit real number, where specifies the number of significant bits and can range between 1 and 53. If you use the FLOAT(n) data type, and is smaller than 25, the 32-bit REAL data type is used instead. If is greater than or equal to 25, or if is not declared, the 64-bit DOUBLE data type is used.

DOUBLE The DOUBLE data type specifies a double-precision 64-bit floating-point number SQL type. See the section below for range information.|

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 11 DECIMAL type notes

Due to protocol restrictions (binary representation as decfloat) the maximum precision of decimal data when accessing it via specific client protocols may be restricted to 34 digits (silent rounding or truncation). SAP Vora disk and in-memory engine, and SAP HANA use different calculation strategies when encountering interim result overflow conditions leading to differences in precision and (overflow) limits in this case. All engines calculate precise results for precise calculations which data is not exceeding the maximum value of the given precision.

DOUBLE type notes

The DOUBLE data type specifies a double-precision 64-bit floating-point number. Subnormal double values [4.94065645841246544E-324,2.2250738585072014E-308] and [-4.94065645841246544E-324, -2.2250738585072014E-308] may be silently converted to +-0.0 respectively in the storage of some engines (e.g. disk engine), but may be produced as results or interim results. Input values closer to +-0.0 than the supported smallest data may be silently converted to +-0.0.

SAP Vora supports the full range of positive normal double values 2.2250738585072014E-308 to 1.7976931348623156E308 () and negative normal double values from -2.2250738585072014E-308 to -1.7976931348623156E308.

 Note

Note that, in line with the SQL standard type definition, the values Not-a-Number (NAN) and Infinity (+- INF) cannot be stored in SAP HANA or SAP Vora. Calculations resulting in +-INF or NAN raise an SQL error. The SAP Vora system does not accept binary double literals.

Example 1:

CREATE TABLE T5(T TINYINT, S SMALLINT, I INT, D DECIMAL(5, 4), R REAL, F FLOAT, DBL DOUBLE) TYPE STREAMING; INSERT INTO T5 VALUES (0, -32768, -2147483648, 3.14, 1.123, -2.456, 56.2342), (255, 32767, 2147483647, 3.14, -0.00003, 0, 1233451.2222222444344);

SELECT * FROM T5;

T S I D R F DBL

0 -32768 -2147483648 3.1400 1.123 -2.456 56.2342

255 32767 2147483647 3.1400 -3e-05 0 1.23345e+06

Example 2:

CREATE TABLE T6(I INTEGER, D1 DECIMAL, D2 DECIMAL(1, 1), D3 DECIMAL(38, 30)) WITH TYPE STREAMING; INSERT INTO T6 VALUES(100, 123, .1, 124.123);

SELECT * FROM T6;

SQL Reference for SAP Vora in SAP Data Hub 12 PUBLIC SQL Reference for SAP Vora in SAP Data Hub I D1 D2 D3

100 123.0 0.1 124.123000000000000000 000000000000

Example 3:

CREATE TABLE T7(D DOUBLE) WITH TYPE STREAMING; INSERT INTO T7 VALUES (2.2250738585072014E-308), (-2.2250738585072014E-308), (4.94065645841246544E-324), (-4.94065645841246544E-324);

SELECT * FROM T7;

Table 3: D

2.22507e-308

-2.22507e-308

0

0

Other

NODE

The NODE data type is an internal data type that represents a node in a hierarchy tree. It cannot be accessed directly, but can only be used as an argument in a hierarchy function. A SELECT query where the result is not reused, but is returned to the user does the following:

● Filters out any columns of type NODE in case of SELECT. ● Throws an error if a column of type NODE is explicitly mentioned in the projection list.

 Note

Node type and hierarchical functions are currently only supported by the in-memory engine.

Example:

In the assumtion that we have hierarchical data, where each row has a field PRED that stores the ID of the "parent" row:

foo@bar:~$ cat /tmp/hierarchical_data.csv 0,NULL,root 1,0,root_child1 2,0,root_child2 3,2,root_child2_child1

foo@bar:~$

The following data is loaded:

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 13 CREATE TABLE HIERARCHYCAL_TABLE2(ID INTEGER, PRED INTEGER, LABEL VARCHAR(*)) WITH TYPE DATASOURCE ENGINE 'MEMORY'; ALTER TABLE HIERARCHYCAL_TABLE2 ADD DATASOURCE '/tmp/hierarchycal_data.csv' DELIMITED BY ',' NULL 'NULL'; LOAD TABLE HIERARCHYCAL_TABLE2;

SELECT * FROM HIERARCHYCAL_TABLE2;

ID PRED LABEL

0 ? root

1 0 root_child1

2 0 root_child2

3 2 root_child2_child1

This data can now be interpreted as a hierarchy (see Table-Valued Functions [page 108]):

SELECT * FROM HIERARCHY(USING HIERARCHYCAL_TABLE2 U JOIN PRIOR V ON (U.PRED = V.ID) SET NODE) h;

The above select would print the same entries, however the column NODE was added of type Node. It can be used with hierarchical functions. We can, for example, select based on node level:

SELECT LABEL FROM (SELECT LABEL, HIERARCHY_LEVEL(NODE) AS LEVEL FROM HIERARCHY(USING HIERARCHYCAL_TABLE2 U JOIN PRIOR V ON (U.PRED = V.ID) SET NODE) H) B WHERE B.LEVEL = 2;

LABEL

root_child2

root_child1

For more information, see Hierarchy Functions [page 105]

1.3.6 Constant Literals

A constant is a symbol that represents a specific fixed data value.

Type Literal

CHAR A character string constant is enclosed in single quotation marks, for example, 'Brian' or '100'.

INTEGER String of numbers not enclosed in quotation marks, for example, 42 or 123456789

DECIMAL String of numbers containing a decimal point, for example, 123, 123.4

FLOAT String of numbers containing a decimal point, or using scientific notation, for ex­ ample, 123, 123.4, 123.4e2

REAL String of numbers containing a decimal point, or using scientific notation, for ex­ ample, 123, 123.4, 123.4e2

SQL Reference for SAP Vora in SAP Data Hub 14 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Type Literal

DOUBLE String of numbers containing a decimal point or using scientific notation, for ex­ ample, 123, 123.4e2, 12e2

DATE date '2010-01-01'

TIME time '11:00:00.1234567'

TIMESTAMP timestamp '2011-12-31 23:59:59.1234567'

BOOLEAN TRUE and FALSE

Example:

CREATE TABLE T8( C CHAR(10), I INTEGER, D DECIMAL, F FLOAT, R REAL, DBL DOUBLE, A_DATE DATE, T TIME, TS TIMESTAMP, B BOOLEAN) WITH TYPE STREAMING; INSERT INTO T8 VALUES( 'abc', 42, 132, 123.4e3, 123.5, 12e2, '2010-01-01', '11:00:00.1234567', '2011-12-31 23:59:59.1234567', TRUE);

SELECT * FROM T8;

C I D F R DBL A_DATE T TS B

abc 42 132.0 123400 123.5 1200 2010-01-0 11:00:00.1 2011-12-31 TRUE 1 234560 23:59:59.1 234560

1.3.7 Data Type Conversion

Both implicit and explicit data type conversions are allowed in the SAP Vora database.

Explicit Type For information about explicit data type conversion, see Data Type Conversion Conversion Functions [page 102].

Implicit Type When a given set of operand/argument types does not match what an operator/ Conversion function expects, a type conversion is carried out by the SAP Vora database. This conversion only occurs if a relevant conversion is available and if it makes the operation/function executable.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 15 Examples:

CREATE TABLE T9(R REAL) WITH TYPE STREAMING; INSERT INTO T9 VALUES (1), (1.6), (3.4); CREATE TABLE T10(I INT, D DOUBLE) WITH TYPE STREAMING; INSERT INTO T10 SELECT CAST(R AS INTEGER), R FROM T9;

SELECT * FROM T10;

I D

1 1

1 1.6

3 3.4

CAST(R AS INTEGER) is an example of an explicit cast. When the value of R is inserted into a DOUBLE, an implicit cast occurs.

1.4 SQL Statements

Table 4:

Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Create Creates a new Schema schema in the CREATE SCHEMA IF NOT EXISTS Factory; Engine tion Lan­ [page 54] database. guage (DDL)

Drop Deletes a Relational Data Defini- DROP SCHEMA Factory; Schema schema. Engine tion Lan­ -- will not throw an error because of [page 55] IF EXISTS clause: guage DROP SCHEMA IF EXISTS Factory; (DDL)

Relational Data Defini- Set Schema Sets the de­ [page 56] fault schema. SET SCHEMA Factory; Engine tion Lan­ All names with­ guage out a schema (DDL) prefix are as­ sumed to be or are searched for in the de­ fault schema.

SQL Reference for SAP Vora in SAP Data Hub 16 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Statement Primary Use Engine Category Name Case Example

Create Ta­ Creates a table Relational Data Defini- CREATE TABLE Person3 ( ble [page in the data­ Engine tion Lan­ name NVARCHAR(85) NOT NULL PRIMARY 49] base. guage KEY, address NVARCHAR(*), (DDL) birthday DATE

) WITH TYPE DATASOURCE ENGINE 'DISK';

Relational Data Defini- Drop Table Removes a ta­ [page 53] ble from the DROP TABLE Person; Engine tion Lan­ database. guage (DDL)

Relational Data Defini- Create Par­ Creates a new tition Func­ partition func­ CREATE PARTITION FUNCTION PF(I INT) AS Engine tion Lan­ RANGE(I) BOUNDARIES (10, 100, 1000, tion [page tion that can 10000); guage 57] be used by a CREATE PARTITION SCHEME PS1 USING PF; (DDL) partition CREATE TABLE T_P(I INT, C CHAR(20)) scheme. Sup­ WITH TYPE STREAMING ENGINE 'DISK' ported: hash, PARTITIONED BY PS1(I); INSERT INTO T_P VALUES (1, 'ONE'), (3, range, and in­ 'THREE'), (13, 'ONE-THREE'), (78, terval. 'SEVEN-EIGHT') , (456, 'FOUR-FIVE- SIX'), (999, 'nine-nine-nine'), (1000, 'one thousand'), (1001, 'one th. one'), (10001, 'ten th. one');

EXPORT T_P INTO CSV('/tmp/out') REPLACE;

Relational Data Defini- Drop Parti­ Removes a par­ tion Func­ tition function CREATE PARTITION FUNCTION pf52( i INT, Engine tion Lan­ j TIMESTAMP) AS HASH(i) PARTITIONS 5 tion [page from the data­ INTERVAL(j) '1' MINUTE; guage 60] base. DROP PARTITION FUNCTION pf52; (DDL)

Relational Data Defini- Create Par­ Creates a parti­ tition tion schema CREATE PARTITION FUNCTION pf53( i INT, Engine tion Lan­ j TIMESTAMP) AS HASH(i) PARTITIONS 5 Scheme with the given INTERVAL(j) '1' MINUTE; guage [page 59] name based on CREATE PARTITION SCHEME ps52 USING pf53; (DDL) the partition function pro­ vided.

Relational Data Defini- Drop Parti­ Removes a par­ tion tition scheme DROP PARTITION SCHEME ps52; Engine tion Lan­ Scheme from the data­ guage [page 61] base. (DDL)

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 17 Statement Primary Use Engine Category Name Case Example

Create Type Creates an in­ Relational Data Defini- CREATE TABLE T_DISK ( Index [page dex on speci­ Engine tion Lan­ C1 CHAR(255), 62] fied columns of guage C2 VARCHAR(85), a disk engine C3 INT, (DDL) table. C4 TIME, C5 DATE, C6 TIMESTAMP, C7 DECIMAL(15, 2), C8 CHAR(255), C9 VARCHAR(50), C10 INT ) WITH TYPE DATASOURCE; CREATE INDEX default_indx ON t_disk( c1, c8 ); CREATE CMP INDEX idx_cmp ON t_disk( c1, c8 ); CREATE DATE INDEX idx_date ON t_disk( c5 ); CREATE DTTM INDEX idx_dttm ON t_disk( c6 ); CREATE HG INDEX idx_hg ON t_disk( c3, c4, c10 ); CREATE HNG INDEX idx_hng ON t_disk( c7 ); CREATE TIME INDEX idx_time ON t_disk( c4 );

CREATE WD INDEX idx_wd ON t_disk( c9 ) DELIMITED BY 'AB' DELIMITED BY 'CD';

Create View Creates a new Relational Data Defini- CREATE TABLE person4( [page 64] relation with Engine tion Lan­ name INT NOT NULL PRIMARY KEY, the given name guage age INT based on a ) WITH TYPE DATASOURCE ENGINE 'DISK'; (DDL) query. The re­ CREATE VIEW adults AS SELECT * FROM lation can be person4 WHERE age >= 21; SELECT * FROM adults; used like an or­ CREATE VIEW V2 AS SELECT * FROM person4 dinary table. WITH CHECK OPTION;

Relational Data Defini- Drop View Removes a [page 65] view. DROP VIEW adults; Engine tion Lan­ guage (DDL)

Alter Table Attaches an ex­ Relational Data Defini- CREATE TABLE person( Add Data ternal data Engine tion Lan­ name VARCHAR(*), Source source, for ex­ guage forename VARCHAR(*), [page 66] ample, an ex­ age INTEGER (DDL) ternal file, to a ) WITH TYPE DATASOURCE ENGINE 'DISK'; table. ALTER TABLE person ADD DATASOURCE AS UK ZIP('/misc/persons_uk.csv.zip') SKIP 1 DELIMITED BY '|'; ALTER TABLE person ADD DATASOURCE AS US CSV('/misc/persons_us.csv') SKIP 1 DELIMITED BY ',';

LOAD TABLE person;

SQL Reference for SAP Vora in SAP Data Hub 18 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Alter Table Detaches an Drop Data external data ALTER TABLE person ADD DATASOURCE AS Engine tion Lan­ US1 CSV('/misc/persons_us.csv') SKIP 1 Source source from a DELIMITED BY ','; guage [page 74] table. ALTER TABLE person DROP DATASOURCE US1; (DDL)

Alter Table Adds a column Relational Data Defini- CREATE TABLE Person2 ( Add Col­ to a streaming Engine tion Lan­ name VARCHAR(30) NOT NULL PRIMARY KEY, umn [page table. guage address VARCHAR(*) 73] ) WITH TYPE STREAMING ENGINE 'DISK';

(DDL) ALTER TABLE Person2 ADD COLUMN salary BIGINT; Streaming Table

Relational Data Defini- Create Role Creates a new [page 27] role. Only data­ create_role ::= CREATE ROLE role_name Engine tion Lan­ base users guage with the ROLE (DDL) ADMIN system privilege are al­ Access lowed to create Control roles. The specified role name must not be identical to the name of an existing user or role. Roles that are delivered with SAP VORA database: PUBLIC.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 19 Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Create User Creates a new [page 28] database user. CREATE USER MYUSER; Engine tion Lan­ Only database guage users with the (DDL) USER ADMIN system privi­ Access lege are al­ Control lowed to create database users. The specified user name must not be identical to the name of an existing user, role, or schema. Users that are deliv­ ered with SAP VORA data­ base: SYS, SYSTEM.

Relational Data Defini- Alter User Modifies the The following statement disables the database user MYUSER1: [page 29] database user. Engine tion Lan­ CREATE USER MYUSER1; The parameter guage ALTER USER MYUSER1 DEACTIVATE; user_name SELECT * FROM SYS.USERS; (DDL) must specify an existing da­ Access tabase user. Control Only database users with the USER ADMIN system privi­ lege are al­ lowed to alter database users.

SQL Reference for SAP Vora in SAP Data Hub 20 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Drop Role Deletes a role. [page 30] Only database DROP ROLE MYROLE; Engine tion Lan­ users with the guage ROLE ADMIN (DDL) system privi­ lege are al­ Access lowed to drop a Control role. With the system privi­ lege ROLE AD­ MIN, all roles except roles that are deliv­ ered with SAP VORA data­ base can be dropped. Roles that are deliv­ ered with SAP VORA data­ base: PUBLIC.

Relational Data Defini- Drop User Deletes a data­ [page 31] base user. Only DROP USER MYUSER; Engine tion Lan­ database users guage with the USER (DDL) ADMIN system privilege are al­ Access lowed to drop a Control user. With the system privi­ lege USER AD­ MIN, all users except users that are deliv­ ered with SAP VORA data­ base can be dropped. Users that are deliv­ ered with SAP VORA data­ base: SYS, SYSTEM. All granted privi­ leges or roles from this user to another user or role are re­ voked recur­ sively.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 21 Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Grant [page Grants a privi­ 32] lege or a role to GRANT SELECT ON SCHEMA myschema TO Engine tion Lan­ myrole; users and guage other roles. (DDL) The specified users and roles Access must exist be­ Control fore they can be used in a GRANT state­ ment. To use the GRANT statement, the user must have the privilege and the per­ mission to grant that priv­ ilege. All users have the privi­ lege to create objects in their own default schema, which always equals the user name. In the case where schema objects were created by a user, the user has all privi­ leges and may grant all of these privi­ leges to other users and roles.

SQL Reference for SAP Vora in SAP Data Hub 22 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Revoke Revokes a role [page 35] or a privilege REVOKE INSERT ON mytable FROM myrole; Engine tion Lan­ for the speci­ guage fied object (DDL) from a user or role. For users Access without ROLE Control ADMIN privi­ leges, only the user that granted a spe­ cific privilege can revoke it. By default, the SYSTEM user has all the sys­ tem privileges and the PUB­ LIC role. All other users have the PUB­ LIC role by de­ fault. These privileges and roles cannot be revoked. If a role or privilege was granted, it will also be re­ voked. If a role was granted with admin op­ tion or a sys­ tem privilege was granted with grant op­ tion, those will be revoked re­ cursively.

Insert [page Appends new Relational Data Manip­ INSERT INTO rel_tbl VALUES 39] values to an ex­ Engine ulation Lan­ ('foo', 5 , 5.0), isting relational guage ('bar', 6 , 6.1); table. (DML)

Streaming Tables

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 23 Statement Primary Use Engine Category Name Case Example

Upsert Overwrites ex­ Relational Data Manip­ UPSERT INTO rel_tbl VALUES [page 41] isting values in Engine ulation Lan­ ('foo', 5 , 5.0), a relational ta­ guage ('bar', 6 , 6.1) WITH PRIMARY KEY; ble series. (DML)

Streaming Tables

Relational Data Manip­ Update Modifies exist­ [page 43] ing records in a UPDATE rel_tbl SET a = 'foo' WHERE x = Engine ulation Lan­ 2; relational table. guage (DML)

Streaming Tables

Relational Data Manip­ Delete Deletes ac­ [page 44] cording to a fil- DELETE FROM rel_tbl WHERE x = 5; Engine ulation Lan­ ter expression. guage (DML)

Streaming Tables

Relational Data Manip­ Loads all data from files at­ LOAD TABLE person; Engine ulation Lan­ tached to the guage corresponding (DML) data source ta­ ble. Data Source Ta­ bles

Relational Data Manip­ Refresh Ma­ Refreshes the terialized data of a mate­ REFRESH MATERIALIZED VIEW adults; Engine ulation Lan­ View [page rialized view. guage 46] (DML)

Relational Data Manip­ Exporting Stores data Tables from tables or EXPORT (SELECT d FROM t_to_export) AS Engine ulation Lan­ results INTO ORC('/tmp/export.orc') AS [page 47] subqueries guage FILE REPLACE; into files, which (DML) provides differ- ent formats Streaming and storage Tables backends. Data Source Ta­ bles

SQL Reference for SAP Vora in SAP Data Hub 24 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Create Au­ The CREATE Engine tion Lan­ dit Policy AUDIT POLICY CREATE AUDIT POLICY clients_audit AUDITING ALL INSERT, UPDATE, DELETE ON guage [page 81] statement cre­ Clients.PersonalInfo LEVEL INFO; (DDL) ates a new au­ dit policy. Only database users with the sys­ tem privilege AUDIT ADMIN are allowed to create an audit policy. The specified audit policy name must be unique and may not match the name of an existing audit policy.

Relational Data Defini- Drop Audit The DROP AU­ Engine tion Lan­ Policy [page DIT POLICY DROP AUDIT POLICY MYPOLICY; guage 83] deletes an au­ (DDL) dit policy.

Relational Data Query Select The SELECT Engine Language [page 84] statement is SELECT DISTINCT I FROM T1; (DQL) used to re­ trieve informa­ tion from the database.

Relational - Create Pro­ Creates a pro­ Engine cedure cedure. CREATE PROCEDURE my_proc ( OUT O INTEGER) LANGUAGE SQLSCRIPT AS

BEGIN DECLARE A INTEGER; A = 5; LOOP A = A + 1; BREAK; END LOOP;

END

Relational - Drop Proce­ Drops a proce­ Engine dure dure. DROP PROCEDURE my_proc;

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 25 Statement Primary Use Engine Category Name Case Example

Relational Data Defini- Connection Adds a connec­ - Engine tion Lan­ Types for tion to a data­ guage DATA­ source with the (DDL) SOURCE Connection and EX­ Manager PORT with Connection Manager [page 75]

Relational Data Defini- Connection Adds a connec­ - Engine tion Lan­ Types for tion to a data­ guage DATA­ source without (DDL) SOURCE Connection and EX­ Management. PORT with­ out Con­ nection Manage­ ment [page 75]

Related Information

Access Control (DDL) [page 26] Data Manipulation Language (DML) [page 36] Data Definition Language (DDL) [page 48] (DQL) [page 83]

1.4.1 Access Control (DDL)

Related Information

Create Role [page 27] Create User [page 28] Alter User [page 29] Drop Role [page 30] Drop User [page 31] Grant [page 32]

SQL Reference for SAP Vora in SAP Data Hub 26 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Revoke [page 35]

1.4.1.1 Create Role

Creates a role.

Syntax

create_role ::= CREATE ROLE role_name

Description

The CREATE ROLE statement creates a new role. Only database users with the ROLE ADMIN system privilege are allowed to create roles. The specified role name must not be identical to the name of an existing user or role.

Roles that are delivered with SAP VORA database: PUBLIC.

Parameters role_name The name of the new role.

If not enclosed by double quotes, all characters of the parameter are stored in uppercase.

Examples

The following statement creates the role MYROLE:

CREATE ROLE MYROLE;

CREATE ROLE "KeepLowercaseChars";

CREATE TABLE T11(I INT) WITH TYPE DATASOURCE; CREATE ROLE QUERY_T11_ROLE; GRANT SELECT ON T11 TO QUERY_T11_ROLE; CREATE USER "user1"; GRANT QUERY_T11_ROLE TO "user1"; CREATE USER "user2";

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 27 GRANT QUERY_T11_ROLE TO "user2"; SELECT * FROM SYS.ROLES;

SELECT * FROM SYS.GRANTED_ROLES;

The first select statement returns:

ROLE_ID ROLE_NAME CREATOR

145 PUBLIC SYS

100031 QUERY_T8_ROLE SYSTEM

The second select statement returs:

GRANTEE GRANTEE_TYPE ROLE_NAME GRANTOR IS_GRANTABLE

SYSTEM USER PUBLIC SYS FALSE

user1 USER QUERY_T8_ROLE SYSTEM FALSE

user1 USER PUBLIC SYS FALSE

user2 USER QUERY_T8_ROLE SYSTEM FALSE

user2 USER PUBLIC SYS FALSE

1.4.1.2 Create User

Creates a database user.

Syntax

create_user ::= CREATE USER user_name

Description

The CREATE USER statement creates a new database user. Only database users with the USER ADMIN system privilege are allowed to create database users. The specified user name must not be identical to the name of an existing user, role, or schema.

Users that are delivered with SAP VORA database: SYS, SYSTEM.

Parameters user_name

SQL Reference for SAP Vora in SAP Data Hub 28 PUBLIC SQL Reference for SAP Vora in SAP Data Hub The name of the new user. If not enclosed by double quotes, all characters of the parameter are stored in uppercase. This behavior affects login and user authentication.

Examples

The following statement creates the user MYUSER:

CREATE USER MYUSER;

SELECT * FROM SYS.USERS;

USER_ID USER_NAME CREATOR USER_DEACTIVATED

143 SYSTEM SYS FALSE

144 SYS SYS TRUE

100036 MYUSER SYSTEM FALSE

Related Information

Create Role [page 27]

1.4.1.3 Alter User

Modifies a user in the current database.

Syntax

alter_user ::= ALTER USER user_name ACTIVATE | DEACTIVATE

Description

The ALTER USER statement modifies the database user. The parameter user_name must specify an existing database user. Only database users with the USER ADMIN system privilege are allowed to alter database users.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 29 Parameters user_name The name of the database user.

Examples

The following statement disables the database user MYUSER1:

CREATE USER MYUSER1;

ALTER USER MYUSER1 DEACTIVATE;

SELECT * FROM SYS.USERS;

USER_ID USER_NAME CREATOR USER_DEACTIVATED

143 SYSTEM SYS FALSE

144 SYS SYS TRUE

100036 MYUSER1 SYSTEM TRUE

The following statement enables the database user MYUSER2:

CREATE USER MYUSER2;

-- ...

ALTER USER MYUSER2 ACTIVATE;

1.4.1.4 Drop Role

Deletes a role.

Syntax

drop_role ::= DROP ROLE role_name

Description

The DROP ROLE statement deletes a role. Only database users with the ROLE ADMIN system privilege are allowed to drop a role. With the system privilege ROLE ADMIN, all roles except roles that are delivered with SAP VORA database can be dropped.

Roles that are delivered with SAP VORA database: PUBLIC.

SQL Reference for SAP Vora in SAP Data Hub 30 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Parameters role_name Must specify an existing role.

Examples

The following statement drops the role MYROLE1:

CREATE ROLE MYROLE1; -- ...

DROP ROLE MYROLE1;

1.4.1.5 Drop User

Deletes a database user.

Syntax

drop_user ::= DROP USER user_name

Description

The DROP USER statement deletes a database user. Only database users with the USER ADMIN system privilege are allowed to drop a user. With the system privilege USER ADMIN, all users except users that are delivered with SAP VORA database can be dropped. Users that are delivered with SAP VORA database: SYS, SYSTEM. All granted privileges or roles from this user to another user or role are revoked recursively. Drops the user only if it does not own any schemas or objects other than their home schema.

Parameters user_name: Must specify an existing user.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 31 Examples

The following statement drops the user MYUSER3:

CREATE USER MYUSER3; -- ...

DROP USER MYUSER3;

1.4.1.6 Grant

Grants privileges or roles to a user or other roles.

Syntax

grant_statement ::= GRANT system_privilege TO grantee [WITH ADMIN OPTION] | GRANT schema_privilege ON SCHEMA schema_name TO grantee [WITH GRANT OPTION] | GRANT object_privilege ON object_name TO grantee [WITH GRANT OPTION] | GRANT role_name TO grantee [WITH ADMIN OPTION] object_name ::=[schema_name'.']schema_object_name system_privilege ::= AUDIT ADMIN | DATA ADMIN | ROLE ADMIN | USER ADMIN | CREATE SCHEMA schema_privilege ::= ALTER | CREATE ANY | DELETE | DROP | EXECUTE | INDEX | INSERT | REFRESH | SELECT | UPDATE object_privilege ::= ALTER | DELETE | DROP | EXECUTE | INDEX | INSERT

| REFRESH | SELECT | UPDATE

System Privileges

Privilege Description

AUDIT ADMIN Controls setting the AUDIT_ADMIN key in the configuration framework.

DATA ADMIN Authorizes reading all data in system views. It also enables the execution of DDL statements in the database. A user with this privilege cannot select or change data stored in ta­ bles for which they do not have access privileges, but they can drop tables or modify their definitions.

SQL Reference for SAP Vora in SAP Data Hub 32 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Privilege Description

ROLE ADMIN Authorizes the creation and deletion of roles by using the CREATE ROLE and DROP ROLE statements. It also author­ izes granting and revoking of roles.

USER ADMIN Authorizes the creation and modification of users by using the CREATE, ALTER, or DROP USER statements.

CREATE SCHEMA Authorizes the creation of database schemas using the CRE­ ATE SCHEMA statement.

Schema/Object Privileges

Privilege Applies to Description

ALTER Schemas, Tables, Views, Procedures Authorizes ALTER statement for the ob­ ject.

CREATE ANY Schemas, Tables, Views, Procedures Authorizes all CREATE statements for the object.

DELETE Schemas, Tables, Views, Procedures Authorizes DELETE statements for the object.

DROP Schemas, Tables, Views, Procedures Authorizes DROP statements for the object.

EXECUTE Schemas, Procedures Authorizes the execution of SQLScript or database procedures by using the CALL statement.

INDEX Schemas, Tables Authorizes the creation modification or dropping of indexes for the object.

INSERT Schemas, Tables, (Mat) Views Authorizes the INSERT statement for the object. The INSERT and UPDATE privileges are both required on the ob­ ject to allow UPSERT statements to be used.

REFRESH Schemas, Materialized Views Authorizes the REFRESH statement for the object.

SELECT Schemas, Tables, (Mat) Views Authorizes the SELECT statement for the object.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 33 Privilege Applies to Description

UPDATE Schemas, Tables, (Mat) Views Authorizes the UPDATE statement for the object. The INSERT and UPDATE privileges are both required on the ob­ ject to allow UPSERT statements to be used.

Description

The GRANT statement grants a privilege or a role to users and other roles. The specified users and roles must exist before they can be used in a GRANT statement. To use the GRANT statement, the user must have the privilege and the permission to grant that privilege. All users have the privilege to create objects in their own default schema, which always equals the user name. In the case where schema objects were created by a user, the user has all privileges and may grant all of these privileges to other users and roles.

Parameters grantee: Must specify an existing user or role. schema_name: Specifies an existing schema. schema_object_name: Specifies an existing schema object, e.g. table, view, stored procedure.

Examples

Grant the SELECT privilege on any object in myschema to the role myrole:

CREATE SCHEMA MYSCHEMA; -- ... CREATE ROLE MYROLE2; -- ...

GRANT SELECT ON SCHEMA myschema TO myrole2;

Grant the INSERT privilege on the object mytable to myrole3:

CREATE TABLE MYTABLE1(I INT) WITH TYPE STREAMING; -- ... CREATE ROLE MYROLE3; -- ...

GRANT INSERT ON mytable1 TO myrole3;

SQL Reference for SAP Vora in SAP Data Hub 34 PUBLIC SQL Reference for SAP Vora in SAP Data Hub

CREATE USER "user3"; CREATE SCHEMA MYSCHEMA1; GRANT AUDIT ADMIN TO "user3"; GRANT DATA ADMIN TO "user3"; GRANT ALTER ON SCHEMA MYSCHEMA1 TO "user3"; CREATE ROLE ROLE1; GRANT ALTER ON SCHEMA MYSCHEMA1 TO ROLE1; GRANT ROLE ADMIN TO ROLE1; CREATE TABLE T12(I INT) WITH TYPE STREAMING; GRANT SELECT ON T12 TO ROLE1 WITH GRANT OPTION; GRANT ROLE1 TO "user3";

GRANT INSERT ON T12 TO ROLE1 WITH GRANT OPTION;

1.4.1.7 Revoke

Revokes a role or a privilege.

Syntax

revoke_statement ::= REVOKE system_privilege FROM grantee | REVOKE schema_privilege ON SCHEMA schema_name FROM grantee | REVOKE object_privilege ON object_name FROM grantee | REVOKE role_name FROM grantee object_name ::= [schema_name'.']schema_object_name system_privilege ::= AUDIT ADMIN | DATA ADMIN | ROLE ADMIN | USER ADMIN schema_privilege ::= ALTER | CREATE ANY | DELETE | DROP | EXECUTE | INDEX | INSERT | SELECT | UPDATE

object_privilege ::= ALTER | DELETE | DROP | EXECUTE | INDEX | INSERT | SELECT | UPDATE

Description

The REVOKE statement revokes a role or a privilege for the specified object from a user or role. For users without ROLE ADMIN privileges, only the user that granted a specific privilege can revoke it. By default, the SYSTEM user has all the system privileges and the PUBLIC role. All other users have the PUBLIC role by default. These privileges and roles cannot be revoked. If a role or privilege was granted, it will also be revoked. If a role was granted with admin option or a system privilege was granted with grant option, those will be revoked recursively. For more, see the Grant [page 32] statement.

Parameters grantee: Must specify an existing user or role. schema_name:

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 35 Specifies an existing schema. schema_object_name: Specifies an existing schema object, e.g. table, view, stored procedure.

Examples

Revoke the SELECT privilege on any object in myschema from the role:

CREATE SCHEMA myschema3; -- ... CREATE ROLE myrole5; -- ...

REVOKE SELECT ON SCHEMA myschema3 FROM myrole5;

Revoke the INSERT privilege on the object mytable from the role:

CREATE TABLE MYTABLE2(I INT) WITH TYPE STREAMING; -- ... CREATE ROLE MYROLE4; -- ...

REVOKE INSERT ON mytable2 FROM myrole4;

1.4.2 Data Manipulation Language (DML)

Data manipulation statements enable you to manipulate data within the SAP Vora database.

Related Information

Load Table [page 37] Insert [page 39] Upsert [page 41] Update [page 43] Delete [page 44] Refresh Materialized View [page 46] Exporting Tables [page 47]

SQL Reference for SAP Vora in SAP Data Hub 36 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.4.2.1 Load Table

Syntax

load_table ::= LOAD TABLE table_name ([RELOAD ALL] [on_error_option]) | ([on_error_option] [RELOAD ALL])

on_error_clause ::= ON ERROR CONTINUE | ABORT

Description

Loads all data from files attached to the corresponding data source table. This statement is only valid for tables defined as datasource tables.

 Note

The LOAD TABLE statement checks whether files are being added to or deleted from the list of data sources since the last execution of the load statement. Only the relevant files are loaded or removed.

The system doesn’t recognize changes to the content of individual files. Hence, files attached to data sources must not be modified after they have been initially loaded to the data source table. If the content of files is changed, the behavior is undefined and may lead to inconsistent data.

The LOAD TABLE statement transitions changes in the datasource definition of the table (ADD / DROP Datasource) to the state of the table during runtime.

For the files engine, the directory is scanned and relevant files are added (ADD DATASOURCE) or removed (DROP DATASOURCE). The data for added files are loaded for datasource tables on the disk engine and relational engine. Only the relevant files are loaded if files were only added.

Dropping datasources may retrigger a complete reload of the table data.

Depending on the ON RELOAD mode of the datasource definition, actions are taken for already added datasources. See the section on Datasource ON REPEATED LOAD Option at Alter Table Add Data Source [page 66].

The file system state during the load operation (list of files with modification timestamp) is persisted and cross-checked for further reference.

The file system source data underneath data sources may not be modified during operation. The system will detect modification on a subsequent access and abort this transaction if the filesystem is not in the state registered during LOAD.

LOAD TABLE table_name RELOAD ALL

Rescans the file system and reloads the data for the given table for all datasources. A prior state of the file system is forgotten and the current state of the file system (files and timestamps) is registered. For disk engine and relational in-memory engine datasource tables, the data is reloaded into the system.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 37 If the LOAD TABLE statement execution is aborted, the load statement has no effect, that is, the table's state is the same as it was before the load statement was executed.

Parameters table_name Local or schema qualified name of the table on_error_option Specifies how to handle potential errors.

 Note

This option is deprecated and retained for compatiblity reasons for disk engine and relational in-memory engine datasource tables. It is recommended to specify this per datasource on the ALTER TABLE table_name ADD DATASOURCE statement.

Options:

● ON ERROR CONTINUE: Loading is not stopped if an error occurs. The respective line/value in the file is skipped. ● ON ERROR ABORT: The command fails if there is an error while loading from the file. This is the default option.

See the section on Datasource ON ERROR Option at Alter Table Add Data Source [page 66].

Examples

The following file (the following extract is from a shell) exists: foo@bar:~$ cat /tmp/file.csv this is some comment, which should be skipped 1,2.4 2,4.9 3,6.1 foo@bar:~$

Loading data into the table: CREATE TABLE TABLE1(I INT, D DOUBLE) WITH TYPE DATASOURCE; ALTER TABLE TABLE1 ADD DATASOURCE CSV('/tmp/file.csv') DELIMITED BY ',' SKIP 2; LOAD TABLE TABLE1; SELECT * FROM TABLE1;

I D

1 2.4

2 4.9

3 6.1

SQL Reference for SAP Vora in SAP Data Hub 38 PUBLIC SQL Reference for SAP Vora in SAP Data Hub If a datasource is modified (for example, more rows are added to the source file), a RELOAD should be issued to bring the new data in: LOAD TABLE TABLE1 RELOAD ALL;

Skip errors (notice second row contains an invalid value): foo@bar:~$ cat /tmp/file1.csv 12321, 55.5 12324s, 55.33 12324, 55.33 foo@bar:~$ ALTER TABLE TABLE1 ADD DATASOURCE '/tmp/file1.csv'; LOAD TABLE TABLE1 ON ERROR CONTINUE;

I D

12321 55.5

? 55.33

12324 55.33

1.4.2.2 Insert

Appends new values to a streaming table.

Syntax

insert_statement ::= INSERT INTO table_name insert_columns_and_source insert_columns_and_source ::= from_subquery | from_constructor | from_default from_constructor ::= VALUES row_value_expression_list from_default ::= DEFAULT VALUES row_value_expression_list ::= value_expression {',' value_expression}

value_expression ::= (val {',' val })

Description

The INSERT statement appends new values to an existing streaming table. If the table has a primary key constraint, all rows violating the primary key constraint are ignored during the execution of the INSERT statement.

 Note

Rows violating primary key constraints are not inserted into the table.

For columns of type CHAR, only valid ASCII characters can be used.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 39 Parameters

table_name Local or schema qualified name of the table. from_query A query expression. See the Select [page 84] statement. value_expression A set of values that match the number, order, and types of the columns from table. val A single value.

Examples

The INSERT statement appends new values to an existing relational table.

Inserting into a streaming table:

CREATE TABLE REL_TBL(S CHAR(3), I INTEGER, D DOUBLE) WITH TYPE STREAMING; INSERT INTO rel_tbl VALUES ('foo', 5 , 5.0), ('bar', 6 , 6.1);

SELECT * FROM REL_TBL;

Result:

S I D

foo 5 5

bar 6 6.1

Inserting default values:

INSERT INTO rel_tbl DEFAULT VALUES;

SELECT * FROM REL_TBL;

S I D

foo 5 5

bar 6 6.1

? ? ?

Inserting from a subquery:

CREATE TABLE SOME_T(I INT, D DOUBLE) WITH TYPE STREAMING; INSERT INTO SOME_T SELECT I, D FROM REL_TBL;

SELECT * FROM SOME_T;

SQL Reference for SAP Vora in SAP Data Hub 40 PUBLIC SQL Reference for SAP Vora in SAP Data Hub I D

5 5

6 6.1

? ?

CREATE TABLE SOME_T2(I INT PRIMARY KEY, D DOUBLE) WITH TYPE STREAMING; INSERT INTO SOME_T2 VALUES(1, 1), (2, 2), (1, 3), (3, 4);

SELECT * FROM SOME_T2;

I D

1 1

2 2

3 4

1.4.2.3 Upsert

Inserts new rows or updates values in existing rows.

Syntax

upsert_statement ::= UPSERT INTO table_name from_constructor WITH PRIMARY KEY from_constructor ::= VALUES row_value_expression_list row_value_expression_list ::= value_expression {',' value_expression}

value_expression ::= (val {',' val })

Description

Upsert works only on tables with a primary key defined. If a row within an UPSERT statement against a given table contains primary key values that are already contained in a row of the table, then the row in the table is updated with the values of the row in the UPSERT statement. Otherwise, the row in the UPSERT statement is inserted as a new row into the table. All columns need to be specified when using an UPSERT statement.

 Note

For columns of type CHAR, only valid ASCII characters can be used.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 41 Parameters table_name Local or schema qualified name of the table. search_condition A search predicate on the table. value_expression A set of values that match the number, order and types of the columns from table. val A single value.

Example

A table with the following CREATE TABLE statement and the content of the table displayed below it, would be updated with the given upsert statement.

The table with a name, address and birthdate:

CREATE TABLE Person ( name VARCHAR(85) NOT NULL PRIMARY KEY, address VARCHAR(*), birthday DATE

) WITH TYPE STREAMING ENGINE 'DISK';

The content of the table contains a name (Bob) and address (Somewhere) and a birthdate (29th April 2000):

Name Address Birthday

bob somewhere 2000-04-29

The following UPSERT statement is used:

UPSERT INTO Person VALUES ('alice', 'foo street', '1978-03-15'),

('bob', 'bar square', '2000-04-30') WITH PRIMARY KEY;

The previous table is then changed to include the new row.

Name Address Birthday

bob bar square 2000-04-30

alice foo street 1978-03-15

SQL Reference for SAP Vora in SAP Data Hub 42 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.4.2.4 Update

The UPDATE statement modifies existing records.

Syntax

update_statement ::= UPDATE table_name [AS] identifier | [[AS] identifier] [SET set_clause_list] [where_clause] set_clause_list ::= set_clause {',' set_clause_list} where_clause ::= WHERE search_condition set_clause ::= (multiple_column_assignment | identifier_chain = '(' value_expression ')') identifier_chain ::= identifier {'.' identifier} multiple_column_assignment ::= '(' identifier_chain {',' identifier_chain} ')' = '(' value_expression ')'

value_expression ::= (val {',' val })

Description

 Note

For columns of type CHAR, only valid ASCII characters can be used.

Updates on partition or primary key columns are not allowed.

Parameters table_name Local or schema qualified name of the table. search_condition A search predicate on the table. val A single value.

Example

The UPDATE command modifies existing records in a relational table.

UPDATE in a streaming table:

CREATE TABLE rel_tbl1 (a CHAR(10), x INTEGER) WITH TYPE STREAMING;

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 43

INSERT INTO rel_tbl1 VALUES('aaa', 1), ('bbb', 2), ('ccc', 3);

SELECT * FROM rel_tbl1;

a x

aaa 1

bbb 2

ccc 3

UPDATE rel_tbl1 SET a = 'foo' WHERE x = 2;

SELECT * FROM rel_tbl1;

a x

aaa 1

foo 2

ccc 3

UPDATE rel_tbl1 AS t SET t.a = 'bar';

SELECT * FROM rel_tbl1;

A X

bar 1

bar 2

bar 3

UPDATE rel_tbl1 SET (a, x) = ('abc', 123);

A X

abc 123

abc 123

abc 123

1.4.2.5 Delete

Deletes certain rows.

Syntax

delete_statement ::= DELETE FROM table_name [ [[AS] identifier] | [[AS] indetifier] where_clause ]

where_clause ::= WHERE search_condition

SQL Reference for SAP Vora in SAP Data Hub 44 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Description

 Note

If no predicate is provided in the DELETE command, the complete content of the table is deleted.

The DELETE statement deletes according to a filter expression.

Parameters table_name Local or schema qualified name of the table. search_condition A search predicate on the table.

DELETE from a streaming table:

CREATE TABLE rel_tbl2 (a CHAR(10), x INTEGER) WITH TYPE STREAMING; INSERT INTO rel_tbl2 VALUES('aaa', 1), ('bbb', 2), ('ccc', 3);

SELECT * FROM rel_tbl2;

a x

aaa 1

bbb 2

ccc 3

DELETE FROM rel_tbl2 WHERE x = 1;

SELECT * FROM rel_tbl2;

a x

bbb 2

ccc 3

DELETE FROM rel_tbl2;

SELECT * FROM rel_tbl2;

a x

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 45 1.4.2.6 Refresh Materialized View

Refreshes the data of a materialized view.

Syntax

refresh ::= REFRESH MATERIALIZED VIEW [schema_name'.']view_name

Description

The REFRESH statement refreshes the data of a materialized view. See Create View [page 64] for more information.

Parameters

The name of the materialized view. The schema of the materialized view. If a schema name is not provided, the materialized view is searched for in the current schema.

Example

In the following example we create a materialized view over a table, then refresh it once the contents of the table changes:

CREATE TABLE tt(i INT) WITH TYPE DATASOURCE; CREATE MATERIALIZED VIEW view1 AS SELECT * FROM tt WHERE tt.i = 2 STORE IN MEMORY; ALTER TABLE tt ADD DATASOURCE '/tmp/in.txt'; LOAD TABLE tt;

SELECT * FROM view1;

The select ouput:

i

REFRESH MATERIALIZED VIEW view1;

SELECT * FROM view1;

SQL Reference for SAP Vora in SAP Data Hub 46 PUBLIC SQL Reference for SAP Vora in SAP Data Hub We now see some data:

i

1

2

3

1.4.2.7 Exporting Tables

Store data from tables or subqueries into files.

Syntax

export_table ::= EXPORT table_primary INTO export_pipeline options table_primary ::= table_name | '(' subquery ')' AS alias export_pipeline ::= exp_format '(' exp_resource ')' [USING CONNECTION connection_id]

options ::= | AS FILE | AS DIRECTORY | REPLACE | FORMAT format_options

Description

The EXPORT statement allows to store data from tables (data source or streaming) or subqueries into files providing different formats and storage backends. The data can be exported into a single file or into a directory with a file for each of the table's partitions.

Parameters

The file format to save to. Supported files are PARQUET, ORC and CSV. Specifies the storage backend and path where the exported data is saved. It consists of a location string surrounded by an optional backend with parentheses (see examples below). If no backend is specified, a path in the local file system is assumed. For more information about data sink resources (files, HDFS/WEBHDFS, S3, ADLS, GCS, WASB) see Connection Types for DATASOURCE and EXPORT without Connection Management [page 75] and Connection Types for DATASOURCE and EXPORT with Connection Manager [page 75].

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 47 Loading options depend on the data sink format, see the DDL Column Options section at Alter Table Add Data Source [page 66]. Specifies the name of a predefined connection. See Connection Types for DATASOURCE and EXPORT with Connection Manager [page 75] for details.

Examples

Export the d column of table t_to_export into ORC format in a local file, possibly overwriting an exisiting file:

CREATE TABLE t_to_export(i INT, d DOUBLE) WITH TYPE STREAMING;

-- ...

EXPORT (SELECT d FROM t_to_export) AS results INTO ORC('/tmp/export.orc') AS FILE REPLACE;

Export the table t_to_export into CSV files on an HDFS node, with '|' as column separator:

EXPORT (SELECT id,name FROM t_region) INTO CSV(HDFS('hdfs:// :/path/to/export-csv'));

EXPORT t_region INTO CSV(HDFS('hdfs://:/path/to/export-csv')) AS DIRECTORY FORMAT SEPARATED BY '|';

Export the customers table into export/customers.csv using a predefined S3 connection named s3_conn:

EXPORT customers INTO CSV('export/customers.csv') USING CONNECTION 's3_conn' AS FILE;

1.4.3 Data Definition Language (DDL)

Data definition statements define structures in the SAP Vora database.

Related Information

Create Table [page 49] Drop Table [page 53] Create Schema [page 54] Drop Schema [page 55] Set Schema [page 56] Create Partition Function [page 57] Create Partition Scheme [page 59] Drop Partition Function [page 60]

SQL Reference for SAP Vora in SAP Data Hub 48 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Drop Partition Scheme [page 61] Create Type Index [page 62] Create View [page 64] Drop View [page 65] Alter Table Add Data Source [page 66] Alter Table Add Column [page 73] Alter Table Drop Data Source [page 74] Connection Types for DATASOURCE and EXPORT with Connection Manager [page 75] Connection Types for DATASOURCE and EXPORT without Connection Management [page 75] Create Audit Policy [page 81] Drop Audit Policy [page 83]

1.4.3.1 Create Table

Creates a new table in the database.

Syntax

create_table ::= CREATE TABLE [IF NOT EXISTS] [schema_name'.']table_name table_content WITH option_list [partition_clause] table_content ::= '(' table_element {',' table_element } ')' partition_clause ::= PARTITION BY partition_scheme_name column_list_clause table_element ::= ( column_definition [ column_constraint ] [ dictionary_clause ]) | table_constraint option_list ::= option { option_list} column_list_clause ::= identifier_chain {, column_list_clause} column_definition ::= column_name data_type column_constraint ::= nullable_clause | primary_key_clause dictionary_clause ::= DICTIONARY ENCODED | NOT DICTIONARY ENCODED table_constraint ::= PRIMARY KEY '(' column_name {, column_name } ')' option ::= table_type_clause | engine_name identifier_chain ::= identifier {'.' identifier} data_type ::= DATE | TIME | TIMESTAMP | CHAR | VARCHAR | TINYINT | SMALLINT | INTEGER | BIGINT | DECIMAL | REAL | FLOAT | DOUBLE nullable_clause ::= NULL | NOT NULL primary_key_clause ::= PRIMARY KEY table_type_clause ::= TYPE (DATASOURCE | STREAMING)

engine_name ::= ENGINE ( 'MEMORY' | 'DISK' | 'FILES' )

Description

The CREATE TABLE statement creates a new table.

 Restriction

The number of columns in the disk engine is limited to 1000.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 49  Note

STORE IN MEMORY|STORE ON DISK syntax is deprecated. Please see the updated syntax:

STORE IN MEMORY -> ENGINE 'MEMORY';

STORE ON DISK -> ENGINE 'DISK'.

As a consequence of this syntax update, all the options of table creation, including table_type_clause follow the WITH keyword:

 Sample Code

CREATE TABLE T(I INT) TYPE DATASOURCE -> CREATE TABLE T(I INT) WITH TYPE DATASOURCE; CREATE TABLE T(I INT) TYPE STREAMING -> CREATE TABLE T(I INT) WITH TYPE STREAMING; CREATE TABLE T(I INT) TYPE STREAMING STORE ON DISK -> CREATE TABLE T(I INT) WITH TYPE STREAMING ENGINE 'DISK' or

... WITH ENGINE 'DISK' TYPE STREAMING.

See more examples below.

Parameters

table_name The name of the new table to be created. schema_name The schema of the new table. If a schema name is not provided, the table is created in the current schema.

● IF NOT EXISTS By default, the command fails if there is already a schema with the same name. This error can be suppressed by specifying IF NOT EXISTS. table_constraint A table can have the following types of constraints:

● PRIMARY KEY A table can have at most one primary key constraint. The primary key is defined by the list of columns provided.

 Restriction

Only the disk engine supports the column constraint PRIMARY KEY.

The disk engine supports composite primary keys with a maximum of 5300 bytes. A primary key with more than 255 bytes can cause longer loads and an increase in database space usage.

SQL Reference for SAP Vora in SAP Data Hub 50 PUBLIC SQL Reference for SAP Vora in SAP Data Hub  Note

The disk engine does not support single-column primary key creation on CHAR columns longer than 255 and on VARCHAR columns longer than 85.

Primary Key Length versus Using larger primary keys Size increases the total size of the table.

Total used disk space = compressed data + ( pri­ mary key length per row * row count) + meta data.

Primary Key Length versus Using larger primary keys Load Time increases the execution time of a load table query.

Constraints are checked on any modification of the table. If a constraint fails, the command violating the constraints also fails. table_type_clause SAP Vora supports different types of tables:

● TYPE DATASOURCE: Data source tables are attached to files on the file system. The content of a data source table cannot be modified. New files, however, can be attached to or detached from a data source table. ● TYPE STREAMING: Streaming tables can be modified by INSERT, UPSERT, UPDATE and DELETE statements. They do not support loading of data sources.

 Note

It is required to always define a valid table type. See Table Types for more information.

Engines SAP Vora supports the following engines:

● DISK: The table is stored in the SAP Vora disk engine. ● MEMORY: The table is stored in the SAP Vora in-memory engine. ● FILES: The data stays in the files that are attached as datasources, while some metadata is stored in-memory.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 51  Note

Currently the files engine has to be actively enabled by the user. To do this, apply the following query in your SQL editor:

ALTER SYSTEM ALTER CONFIGURATION ('vora', 'system’) SET ('semantic', 'enable_sql_on_files') = 'true' WITH RECONFIGURE

The default engine for a table is the disk engine. partition_clause A table can be partitioned using a partition schema. In this case, the name of the partition schema is specified by partition_scheme_name, and the columns used for partitioning are specified by column_list_clause. All columns of the primary key must be part of the partitioning. A table is not partitioned by default. nullable_clause A column of a table can be defined as either of the following:

● NULL: The column is assumed to be nullable, that is, it can have the value NULL, indicating that the value of the column is undefined. ● NOT NULL: The column is not nullable, that is, it cannot have the value NULL, indicating that the value of the column is undefined.

The default is NULL. Only columns that are not nullable can be part of the primary key of the table. It is recommend that you use the NOT NULL constraint wherever possible. primary_key_clause A table can have at most one column marked as PRIMARY KEY. Only columns that are not nullable can be the primary key of the table. For the disk engine, the maximal size of a primary key is 255 bytes. dictionary_clause A column of a table can be defined as either of the following:

● DICTIONARY ENCODED: The column is stored using a dictionary, i.e. using a first structure storing only the distinct values of the columns and a second structure containing only references to those unique values. ● NOT DICTIONARY ENCODED: The column is not dictionary encoded.

The default is NOT DICTIONARY ENCODED. Only columns of type CHAR and VARCHAR stored in the in-memory relational engine can be dictionary encoded. In general, dictionary encoding is benefecial if the column contains less than 64000 distinct values and the average length of the values is larger 2.

Examples

The following example defines a simple table of type data source that is stored on the disk engine with three columns. The primary key of the table is (name).

CREATE TABLE Person3 (

SQL Reference for SAP Vora in SAP Data Hub 52 PUBLIC SQL Reference for SAP Vora in SAP Data Hub name NVARCHAR(85) NOT NULL PRIMARY KEY, address NVARCHAR(*), birthday DATE

) WITH TYPE DATASOURCE ENGINE 'DISK';

Alternatively, the primary key constraint can be defined as follows:

CREATE TABLE Person1 (

name NVARCHAR(85) NOT NULL, address NVARCHAR(*), birthday DATE, PRIMARY KEY(name)

) WITH TYPE DATASOURCE ENGINE 'DISK';

The following example defines a table of type streaming on the disk engine with three columns.

CREATE TABLE Place (

street NVARCHAR(*), zip INT, country NVARCHAR(100)

) WITH TYPE STREAMING ENGINE 'DISK';

Creating a table only if does not already exist, otherwise ignore:

CREATE TABLE IF NOT EXISTS ttt(i INT) WITH TYPE DATASOURCE;

CREATE TABLE IF NOT EXISTS ttt(i INT) WITH TYPE DATASOURCE;

Creating the table in a specific schema:

CREATE TABLE TTT1(I INT) WITH TYPE DATASOURCE; CREATE SCHEMA SSS;

CREATE TABLE SSS.TTT1(I INT) WITH TYPE DATASOURCE;

CREATE TABLE tab_with_primary_key(c CHAR(5000), C2 CHAR(298), PRIMARY KEY(C, C2)) WITH TYPE STREAMING;

The following example defines a table of type datasource on the files engine with three columns.

CREATE TABLE Place (

street NVARCHAR(*), zip INT, country NVARCHAR(100)

) WITH TYPE DATASOURCE ENGINE 'FILES';

1.4.3.2 Drop Table

Removes a table from the database.

Syntax

drop_table ::= DROP TABLE [schema_name'.']table_name

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 53 Description

The DROP TABLE statement drops the table with the given name.

Parameters table_name The name of the table to be dropped. schema_name The schema of the table. If a schema name is not provided, the table is searched for in the current schema.

Examples

The following statement drops the table Person1:

DROP TABLE Person1;

1.4.3.3 Create Schema

Creates a schema in the current database.

Syntax

create_schema ::= CREATE SCHEMA [IF NOT EXISTS] schema_name

Description

The CREATE SCHEMA statement creates a new schema with the given name.

Parameters schema_name

SQL Reference for SAP Vora in SAP Data Hub 54 PUBLIC SQL Reference for SAP Vora in SAP Data Hub The name of the new schema. IF NOT EXISTS By default, the command fails if there is already a schema with the same name. This error can be suppressed by specifying IF NOT EXISTS.

Examples

The following statement creates the schema Factory provided there isn't already a schema with the same name:

CREATE SCHEMA IF NOT EXISTS Factory;

1.4.3.4 Drop Schema

Removes a schema.

Syntax

drop_schema ::= DROP SCHEMA [IF EXISTS] schema_name

Description

The DROP SCHEMA statement drops the schema with the given name. The command fails if the schema does not exist. By default, all objects residing in the schema are also dropped. Any object that depends on the schema or its objects becomes invalid.

Parameters schema_name The name of the schema to be deleted. IF EXISTS Checks if the schema exists before trying to drop it. If It does not exist, the statement is ignored.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 55  Note

The initial default schema is the VORA schema. If the current default schema is dropped, the default schema is set to VORA again.

Examples

The following statement drops the Factory schema:

DROP SCHEMA Factory; -- will not throw an error because of IF EXISTS clause:

DROP SCHEMA IF EXISTS Factory;

1.4.3.5 Set Schema

Sets the default schema.

Syntax

set_schema ::= SET SCHEMA schema_name

Description

The SET SCHEMA statement sets the default schema. All names without a schema prefix are assumed to be or are searched for in the default schema.

Parameters schema_name The name of the default schema.

 Note

The initial default schema is the VORA schema. If the current default schema is dropped, the default schema might refer to a schema that no longer exists. It is therefore advisable to use SET SCHEMA to re- initialize the default schema to an existing schema.

SQL Reference for SAP Vora in SAP Data Hub 56 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Examples

The following statement makes the Factory schema the default schema:

SET SCHEMA Factory;

1.4.3.6 Create Partition Function

Creates a new partition function.

Syntax

create_pf ::= CREATE PARTITION FUNCTION [schema_name'.']pf_name ( pf_parameter_list ) AS pf_def_list_auto pf_def_list_auto ::= (pf_definition_list ',' AUTO | (pf_definition_list | AUTO)) pf_parameter_list ::= column_name data_type {, pf_parameter_list} pf_definition_list ::= pf_definition { pf_definition_list } pf_definition ::= pf_range | pf_hash | pf_interval pf_range ::= RANGE ['(' identifier_chain ')'] boundary_def pf_hash ::= HASH ['(' identifier_chain { , identifier_chain } ')'] [MIN PARTITIONS unsigned_integer] [PARTITIONS unsigned_integer] [AS identifier] pf_interval ::= INTERVAL '(' identifier_chain ')' [ '-'|'+' ] interval_string_literal interval_qualifier boundary_def ::= BOUNDARIES '(' [value_expression { , value_expression }] ')' identifier_chain ::= identifier {'.' identifier} interval_qualifier ::= ( datetime_field [ '(' unsigned_integer ')' ] TO end_field ) | end_field end_field ::= datetime_field | SECOND'('unsigned_integer')' ]

datetime_field ::= (DAY|HOUR|MINUTE)

The interval for pf_interval must comply with the following rules:

● Duration must be more than 60 seconds

The following are examples of valid intervals: '15' minutes or '12 2' day to hour

Description

The CREATE PARTITION FUNCTION statement creates a new partition function that can be used by a partition scheme. The following types are partition function are supported: hash, range, and interval.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 57 Parameters pf_name The name of the new partition function to be created. schema_name The schema of the new partition function. If a schema name is not provided, the partition function is created in the current schema. column_name The parameter for the partition function. pf_range For range partitioning, the individual ranges must be specified by denoting the individual ranges of the partition, for example, RANGE(height) BOUNDARIES (2, 4, 6, 7) defines 4 partitions. pf_hash For hash partitioning, the number of partitions must be explicitly provided, for example, HASH(x, y) PARTITIONS 7 defines 7 partitions. interval_string_literal A numeric represenation of an interval, like '2' or '12', etc.

Examples

Here's an example how data is partitioned:

CREATE PARTITION FUNCTION PF(I INT) AS RANGE(I) BOUNDARIES (10, 100, 1000, 10000); CREATE PARTITION SCHEME PS1 USING PF; CREATE TABLE T_P(I INT, C CHAR(20)) WITH TYPE STREAMING ENGINE 'DISK' PARTITIONED BY PS1(I); INSERT INTO T_P VALUES (1, 'ONE'), (3, 'THREE'), (13, 'ONE-THREE'), (78, 'SEVEN- EIGHT') , (456, 'FOUR-FIVE-SIX'), (999, 'nine-nine-nine'), (1000, 'one thousand'), (1001, 'one th. one'), (10001, 'ten th. one');

EXPORT T_P INTO CSV('/tmp/out') REPLACE;

In /tmp/out each partition has its own subdirectory, and the inserted data is partitioned accordingly:

partition 2: 10 <= i < partition 3: 100 <= i < partition 4: 1000 <= i partition 1: i < 10 100 1000 < 10000 partition 5: 10000 < i

1, 3 13, 78 456, 999 1000, 1001 10001

If there are enough hosts or engines, each take their partition. Otherwise, multiple partitions are on the same host.

Divide input into partitions by timestamp - every 2 minutes is a separate partition:

CREATE PARTITION FUNCTION PF2(T TIMESTAMP) AS INTERVAL(T) '2' MINUTE; CREATE PARTITION SCHEME PS2 USING PF2; CREATE TABLE T_PF2(I INT, T TIMESTAMP) WITH TYPE STREAMING PARTITIONED BY PS2(T);

SQL Reference for SAP Vora in SAP Data Hub 58 PUBLIC SQL Reference for SAP Vora in SAP Data Hub INSERT INTO T_PF2 VALUES (1, '1994-01-01 08:00:15'), (2, '1994-01-01 08:00:45'), (3, '1994-01-01 08:01:45'), (4, '1994-01-01 08:02:45'), (5, '1994-01-01 08:10:45'), (6, '1994-01-01 08:23:45');

The following example shows how to combine hash with interval partitioning:

CREATE PARTITION FUNCTION pf51( i INT, j TIMESTAMP) AS HASH(i) PARTITIONS 5 INTERVAL(j) '1' MINUTE; CREATE PARTITION SCHEME ps51 USING pf51;

CREATE TABLE t51(i INT, j TIMESTAMP) WITH TYPE STREAMING ENGINE 'DISK' PARTITIONED BY ps51(i, j);

1.4.3.7 Create Partition Scheme

Creates a new partition scheme.

Syntax

create_ps ::= CREATE PARTITION SCHEME [schema_name1'.']ps_name USING [schema_name2'.']partition_fn [WITH COLOCATION]

Description

The CREATE PARTITION SCHEME statement creates a partition schema with the given name based on the partition function provided.

Parameters ps_name The name of the new partition scheme to be created. schema_name1 The schema of the new partition scheme. If a schema name is not provided, it is assumed to be the current schema. partition_fn The partition function to be used for the new partition scheme. schema_name2 The schema of the partition function. If a schema name is not provided, the current schema is searched. WITH COLOCATION

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 59 "Similar" partitions from different tables can be requested to be colocated. This might be useful to make joins more efficient. By default, partitions are not colocated.

Examples

The following statement creates a partition scheme based on the partition function pf53:

CREATE PARTITION FUNCTION pf53( i INT, j TIMESTAMP) AS HASH(i) PARTITIONS 5 INTERVAL(j) '1' MINUTE;

CREATE PARTITION SCHEME ps52 USING pf53;

Example of using colocation:

CREATE PARTITION FUNCTION PFF(I INT) AS RANGE(I) BOUNDARIES(10, 100, 1000, 10000); CREATE PARTITION SCHEME PSS USING PFF WITH COLOCATION; CREATE TABLE T_P_1(I INT, C CHAR(20)) WITH TYPE STREAMING ENGINE 'DISK' PARTITIONED BY PSS(I); CREATE TABLE T_P_2(I INT, C CHAR(20)) WITH TYPE STREAMING ENGINE 'DISK' PARTITIONED BY PSS(I);

-- T_P_1 and T_P_2 partitions will be colocated.

1.4.3.8 Drop Partition Function

Removes a partition function from the database.

Syntax

drop_pf ::= DROP PARTITION FUNCTION [schema_name'.']pf_name

Description

The DROP PARTITION FUNCTION statement drops the partition function with the given name.

Parameters pf_name The name of the partition function to be deleted. schema_name

SQL Reference for SAP Vora in SAP Data Hub 60 PUBLIC SQL Reference for SAP Vora in SAP Data Hub The schema of the partition function. If a schema name is not provided, the partition function is searched for in the current schema.

Examples

The following statement drops the partition function pf:

CREATE PARTITION FUNCTION pf52( i INT, j TIMESTAMP) AS HASH(i) PARTITIONS 5 INTERVAL(j) '1' MINUTE;

DROP PARTITION FUNCTION pf52;

1.4.3.9 Drop Partition Scheme

Removes a partition scheme from the database.

Syntax

drop_ps ::= DROP PARTITION SCHEME [schema_name'.']ps_name

Description

The DROP PARTITION SCHEME statement drops the partition scheme with the given name.

Parameters

ps_name The name of the partition scheme to be deleted. schema_name The schema of the partition scheme. If a schema name is not provided, the partition scheme is searched for in the current schema.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 61 Examples

The following statement drops the partition scheme ps52:

DROP PARTITION SCHEME ps52;

1.4.3.10 Create Type Index

Creates an index on specified columns of a disk engine table.

Syntax

create_index ::= CREATE [index_type] INDEX index_name ON [schema_name'.']table_name index_element [index_options] | CREATE FULLTEXT INDEX index_name ON [schema_name'.']table_name index_element [fulltext_index_params] | CREATE HASH INDEX index_name ON [schema_name'.']table_name '(' column_name {',' column_name } [ASC | DESC] ')' index_type ::= CMP | HG | HNG | WD | DATE | TIME | DTTM index_options ::= { index_option }

index_option ::= DELIMITED BY delimited_string

Description

The CREATE [TYPE] INDEX statement creates an index on specified columns of a disk engine table.

Parameters index_name The name of the new index to be created. table_name The name of the table where the new index to be created. schema_name The schema of the table. If a schema name is not provided, it uses the current schema. index_element Columns which are used in the index. index_option

An index can have the following types of constraint:

SQL Reference for SAP Vora in SAP Data Hub 62 PUBLIC SQL Reference for SAP Vora in SAP Data Hub ● DELIMITED BY: separators to use in parsing a column string into the words to be stored in the WD index of that column. If it is specified more than once, the last specified one is used. ● delimited_string: A sequence of 0 or more characters ● index_type: IQ Types: ○ CMP: relationship between any two distinct columns with identical data types, precision, and scale.The CMP index stores the binary comparison (<, >, or =) of its two columns ○ DATE: created only on a column having the data type DATE ○ DTTM: created only on a column having the data type TIMESTAMP ○ HG: commonly used for join columns with integer data types ○ HNG: common for range searches ○ TIME: created only on a column having the data type TIME ○ WD: created only on a column having the data type CHAR and VARCHAR fulltext_index_params Full-text indices can be created only on text analysis summary (TADOC_) tables. For more information, see Text Analysis.

 Note

HG index is the default value if type is not specified.

You cannot create an index on a BOOLEAN column.

HNG does not support column types: FLOAT, REAL, or DOUBLE.

HG and CMP supports multi-column indexes.

SAP Vora disk engine does not support index creation on CHAR columns longer than 255 and VARCHAR columns longer than 85.

Examples

CREATE TABLE T_DISK ( C1 CHAR(255), C2 VARCHAR(85), C3 INT, C4 TIME, C5 DATE, C6 TIMESTAMP, C7 DECIMAL(15, 2), C8 CHAR(255), C9 VARCHAR(50), C10 INT ) WITH TYPE DATASOURCE; CREATE INDEX default_indx ON t_disk( c1, c8 ); CREATE CMP INDEX idx_cmp ON t_disk( c1, c8 ); CREATE DATE INDEX idx_date ON t_disk( c5 ); CREATE DTTM INDEX idx_dttm ON t_disk( c6 ); CREATE HG INDEX idx_hg ON t_disk( c3, c4, c10 ); CREATE HNG INDEX idx_hng ON t_disk( c7 ); CREATE TIME INDEX idx_time ON t_disk( c4 );

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 63

CREATE WD INDEX idx_wd ON t_disk( c9 ) DELIMITED BY 'AB' DELIMITED BY 'CD';

1.4.3.11 Create View

Creates a new view.

Syntax

create_view ::= CREATE VIEW view_name AS query |

CREATE MATERIALIZED VIEW view_name AS query [STORE ON DISK | STORE IN MEMORY]

Description

The CREATE VIEW statement creates a new relation with the given name based on a query. The relation can be used like an ordinary table. Currently, only non-updatable views are supported. Streaming tables are therefore not supported.

 Note

The content of a materialized view can become stale if the content of any of the underlying base tables is changed. The system does not provide an automated mechanism for reconciling the data. This must be controlled explicitly by executing the REFRESH MATERIALIZED VIEW statement. When you create a materialized view, it is initially uninitialized (and may be populated via REFRESH MATERIALIZED VIEW).

 Note

A view cannot have two columns with the same alias in its result set.

Parameters view_name The name of the new view to be created. schema_name The schema of the new view. If a schema name is not provided, it is assumed to be the current schema. MATERIALIZED If the view is defined as MATERIALIZED, the data is persisted rather than recomputed whenever it is accessed.

SQL Reference for SAP Vora in SAP Data Hub 64 PUBLIC SQL Reference for SAP Vora in SAP Data Hub STORE ON DISK or STORE IN MEMORY For materialized views, it is mandatory to specify where the materialized data is stored. Two options are currently supported:

● STORE ON DISK: The data is stored in the disk engine. ● STORE IN MEMORY: The data is stored in the relational in-memory engine.

This mandatory clause applies only to materialized views.

Examples

The following statement creates a view on the table person4 and selects all people aged 21 and over:

CREATE TABLE person4( name INT NOT NULL PRIMARY KEY, age INT ) WITH TYPE DATASOURCE ENGINE 'DISK'; CREATE VIEW adults AS SELECT * FROM person4 WHERE age >= 21; SELECT * FROM adults;

CREATE VIEW V2 AS SELECT * FROM person4 WITH CHECK OPTION;

For a materialized view example, see Refresh Materialized View [page 46].

1.4.3.12 Drop View

Removes a view.

Syntax

drop_view ::= DROP VIEW [ schema_name.]view_name

Description

The DROP VIEW statement drops the view with the given name.

Parameters view_name The name of the view to be deleted.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 65 schema_name The schema of the view. If a schema name is not provided, the view is searched for in the current schema.

Examples

The following statement drops the view adults:

DROP VIEW adults;

1.4.3.13 Alter Table Add Data Source

Attaches an external data source, for example, an external file, to a table.

Syntax

add_datasource ::= ALTER TABLE table_name ADD DATASOURCE [ AS datasource_name ] [ ds_column_clause ] datasource_clause [ using_connection_clause ] [ datasource_options ] [ on_error_option ] [ on_repeated_load_option ] datasource_clause ::= ( PARQUET | ORC | AVRO | CSV ) '(' datasource_filter ')' | datasource_filter datasource_filter ::= ZIP '(' datasource_resource ')' | datasource_resource

using_connection_clause ::= USING CONNECTION connection_id

Parameters table_name Name of the table to be altered. datasource_name Optional datasource name. You can reference (for example, drop) the datasource by its name, otherwise a unique name is generated. ds_column_clause Per-column loading options, see DDL Column Options (override the loading options specified in for that specific column). datasource_format

SQL Reference for SAP Vora in SAP Data Hub 66 PUBLIC SQL Reference for SAP Vora in SAP Data Hub The file format to load from. It is only applicable for the relational, files and disk engines. The supported values are PARQUET, ORC, AVRO, and CSV. If not specified, the default format is CSV. Note that for PARQUET and ORC, only files with the extension ".parquet" and ".orc" are considered when specifying folders. datasource_resource For information about data source resources (files, HDFS/WEBHDFS, S3, ADLS, GCS, WASB), see Connection Types for DATASOURCE and EXPORT without Connection Management [page 75]. connection_id The idenitifer of a connection used from the SAP Data Hub Connection Manager, see Connection Types for DATASOURCE and EXPORT with Connection Manager [page 75]. When this is used, datasource_resource is a subpath/file inside the connection. datasource_options Loading options for all columns, see DDL Table Options. on_error_option Determines the behavior on loading or querying w.r.t. non-mappable file content. See Datasource 'ON ERROR' option on_repeated_load_option Default ON REPEATED LOAD ADD NEW FILES, see Datasource ON REPEATED LOAD Options.

Description

The ALTER TABLE ADD DATASOURCE statement can be used to attach an external data source, for example, an external file, to a table. The ALTER statement only maintains metadata and keeps a record of which files are associated with which tables. The ALTER TABLE DROP DATASOURCE statement can be used to remove a data source from the metadata of a table.

 Note

During the execution of the ALTER statement, data is not loaded and the structure and existence of the files are not verified. Instead, the LOAD TABLE statement is used to load the data. In addition, a file that is attached twice to any data source is loaded twice by the related LOAD statement.

DDL Column Options

ds_column_clause ::= '(' ds_column_spec { ',' ds_column_spec } ')' ds_column_spec ::= column_name { ds_column_attributes | ds_csv_column_attributes } ds_column_attributes ::= AS '$'column_index | FROM COLUMN '$'column_index | FROM COLUMN file_column_name | DEFAULT VALUE literal ds_csv_column_attributes ::= DECIMAL SEPARATED BY decimal_separator_char

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 67 | THOUSANDS SEPARATED BY thousand_separator_char | DATE '(' date_format_string ')' | FORMAT date_format_string | NULL null_string | NULL '(' null_string ')'

| ESCAPE CHARACTER escape_char ds_csv_column_attributes are only valid for CSV files.

Elements ending with _char are supposed to be a single character enclosed by single quotes, for example, ','.

Parameters column_name The name of the column on which the options are applied to. AS '$'column_index Use, for example, 'AS $2' to load this column as column 2 from the source file. It can be used to skip columns on load. FROM COLUMN '$'column_index Equivalent to AS '$'column_index. FROM COLUMN file_column_name Identify the column by the column name in the orc/parquet files. file_column_name follows the normal SQL identifier rules, use "CaseSenstive Col1" for a case-sensitive specification. FROM VALUE literal The column will be filled with a constant value for every row in the file. literal_value must be literal value for the column type. DEFAULT VALUE literal The literal values will be used when the datasource is loaded with ON ERROR CONTINUE when encountering a non-mappable value in the original data. See ON ERROR CONTINUE Behaviour. DECIMAL SEPARATED BY decimal_separator_char decimal_separator_char is a single char like '.', which sets the decimal separator. For example, when using German numbers like 3,141, you have to set this to ','. The default is '.'. THOUSANDS SEPARATED BY thousand_separator_char Similarly, you can change the thousands separator to a different value than the default ','. For example, if one million is 1.000.000, set this to '.'. DATE '(' date_format_string ')' For valid uses of date_format_string, see to_date(). Example: DATE('YYYY/DD/ MM'). FORMAT date_format_string For valid uses of date_format_string, see to_date(). NULL null_string

SQL Reference for SAP Vora in SAP Data Hub 68 PUBLIC SQL Reference for SAP Vora in SAP Data Hub By default, values with '?' are considered to be NULL. You can change this to any other string, like 'nil'. Note that the SAP Vora disk engine implicitly accepts NULL (case- sensitive, uppercase) strings as a null value for string columns. NULL '(' null_string ')' Similar to previous option. ESCAPE CHARACTER escape_char Specifies the escape character, that change the meaning of other characters (for example, of delimiter). Key Currently implemented only up to pg/catalog/tc. No engine actually uses this info.

DDL Table Options (CSV Only)

 Note

These options only apply for loading from CSV files.

datasource_options ::= DELIMITED BY delimiter_char | SKIP skip_unsigned_integer | STRING DELIMITED BY string_delimiter_char | NO STRING DELIMITER | DECIMAL SEPARATED BY single_char | THOUSANDS SEPARATED BY single_char | DATE ( date_format_string ) | FORMAT date_format_string | NULL null_string | ESCAPE CHARACTER escape_char

identifier_name_list ::= identifier_name { ',' identifier_name } single_char is a single character enclosed by single quotes, for example, ' '.

Parameters

DELIMITED BY delimiter_char The tuple delimiter between columns of the file. The default is ',', so that "a,b,c" represents 3 columns. SKIP skip_unsigned_integer The number of lines at the beginning of the CSV file to skip, for example, headers. The default is 0 (no skip). STRING DELIMITED BY string_delimiter_char Sets the delimiter for strings, for example, '$', so that you can write $Hello World$. The default is ‘”’. Using the same delimiter for both strings and columns is not allowed. NO STRING DELIMITER With this option, strings are only delimited by a new line and the tuple delimiter (set by DELIMITED BY). Note, that this means that you can’t have new lines in your strings. All

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 69 strings are literally parsed, including quotations. This option is also slightly faster to read than the normal read option. By default, this option is switched off. DECIMAL SEPARATED BY, THOUSANDS SEPARATED BY, DATE, FORMAT, NULL, ESCAPE CHARACTER Reading options for all columns of the file. See ds_column_clause.

 Note

Options specified in ds_column_clause override the loading options specified in datasource_options for that specific column.

Datasource ON ERROR Option

The ON ERROR CONTINUE datasource declaration defines the system behavior for loading or querying data from the datasource.

Capabilities:

● Rectify data on loading into disk engine or relational in-memory engine datasource tables; ● Data discovery in files that do not fully fit the target domain; ● Query data for insertion into streaming tables even if data in the file is not mappable to the SQL type domain.

Using the DEFAULT VALUE addition allows to distinguish between "true" null values present in the files and null values created by the default value conversion.

The following table lists a number of error conditions which lead to abort of the load (or SQL query in case of the files engine) in the default mode (ON ERROR ABORT).

Nr. Error Condition Behavior ON ERROR CONTINUE

1 File not found Abort

2 File has been modified Abort

3 File can not be read Abort

4 Column adressed by index not found Abort (csv,orc, parquet)

5 Column adressed by name not found Abort (csv header, orc, parquet)

6 CSV-Line has fewer columns Undefined

7 Illegal bytes in CHAR/VARCHAR col­ Replaced, see below umn

8 CHAR/VARCHAR input is too long Truncate to column target length

9 Value is outside of the domain range Value conversion

10 Value is NULL but the column is NOT Value conversion NULL

Value conversion in ON ERROR CONTINUE MODE

The default value conversion can be summarized as:

SQL Reference for SAP Vora in SAP Data Hub 70 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Non-character values in the file will be converted to: ● Specified DEFAULT VALUE literal if specified for the col­ umn; ● NULL if no DEFAULT VALUE was specified for the col­ umn and the SQL column type is nullable; ● The type initial value if the SQL column type is NOT NULL.

Character type values will be silently converted to the de­ ● Replacing non-ascii charaters by '#' for CHAR types; sired target type: ● Replacing non-unicode byte-sequences by U+FFFD (UNICODE REPLACEMENT CHARACTER) for VARCHAR types; ● Truncating the resulting string to Nu CodeUnits (VAR­ CHAR(Nu)) / CHAR(Nb) if necessary; ● Truncating or white-space (' ') padding the sequnence to exactly N Bytes (CHAR(N)).

The following table gives an example:

Column Definition DEFAULT VALUE specified Value in file Converted Value

DOUBLE NULL (none) inf NULL

DOUBLE NULL 1.23E+3 inf 1.23E+3

DOUBLE NOT NULL (none) inf +0.0 (*)

DOUBLE NULL NULL 1.23E+3 1.23E+3

VARCHAR(2) NOT NULL (none) NULL ""

VARCHAR(2) NOT NULL (none) "AB" "A"

(*) The initial value corresponding to the type is used.

For non-trivial types the initial values are:

Type Default value

VARCHAR "" (empty string)

CHAR(N) N Spaces

DATE date'1970:01:01'

TIME time'00:00:00'

TIMESTAMP timestamp'1970:01:01 00:00:00'

Illegal bytes rectification for character types

SAP Vora imports data from files as a binary format, assuming the data is stored as UTF-8. SAP Vora does not strip or interpret BOM (byte order marks) from CSV files or support other file encodings.

When illegal byte sequences or too long strings are encountered in ON ERROR CONTINUE mode, in contrast to other types where the value is ignored and fully replaced, individual character replacement and truncation occurs to retain a maximum of data:

● For the CHAR type non-7-Bit ASCII bytes are replaced by '#'

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 71 ● For VARCHAR illegal bytes are replaced by U+FFFD (UNICODE REPLACEMENT CHARACTER)

Column Definition Value in File Converted Value Operation

CHAR(3) "ABC" "ABC"

CHAR(3) "ABCD" "ABC" Truncation

CHAR(3) "äBC" "##B" Replacement

\xC3 \xA4 \x42 \x43

CHAR(3) "(ä)BC" "#BC" Replacement

\xE4 \x42 \x43

CHAR(3) "€BC" "###" Replacement

\xE2 \x82 \xAC \x42 \x43

VARCHAR(3) "ABCD" "ABC" Truncation

VARCHAR(3) "A€CD" "A€C" Truncation

VARCHAR(3) "ABC" "A" Truncation

\x41 \xF0 \xF9 \x98 \x83 U+0041 0xDE03 0xD83E \x42 \x43

VARCHAR(3) "ABC" "A" Truncation

\x41 \xF0 \xF9 \x98 \x83 U+0041 0xDE03 0xD83E \x42 \x43

VARCHAR(3) "AB" "AB�" Truncation (Leading Surro­ gate) \x41 \xF0 \xF9 \x98 \x83 U+0041 U+0042 0xDE03 \x42 \x43

VARCHAR(3) "(ä)BC" "�BC" Truncation

\xE4 \x41 \x42 U+FFFD U+0042 U+0043

 Note

U+XXXX: Unicode codepoint; \xXX byte of input; 0xDE03, 0xD83E : the value of the surrogate pair in UTF-16.

DEFAULT VALUE is not supported for character type column.

Datasource ON REPEATED LOAD Option

on_repeated_load_option ::= ON REPEATED LOAD ( ADD NEW FILES | RECHECK | DO NOTHING )

SQL Reference for SAP Vora in SAP Data Hub 72 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Defines the action taken for an already loaded datasource, when another LOAD TABLE statement is issued for the table.

Parameters

RECHECK A diretory access is performed and existence and identity (via a size and modification timestamp comparison) is checked for the files registered during the initial load. The LOAD statement fails if the filesystem state is not equivalent to the initial load. ADD NEW FILES In addition to the RECHECK actions, additional files found in specified folders are added and loaded. This is the default. DO NOTHING No action is performed for this data source. Primary use is to avoid unnecessary access for large file systems on remote/expensive storages.

1.4.3.14 Alter Table Add Column

Adds a column to a streaming table.

Syntax

add_column ::= ALTER TABLE table_name ADD COLUMN column_definition column_definition ::= column_name data_type data_type ::= DATE | TIME | TIMESTAMP | CHAR | VARCHAR | TINYINT |

SMALLINT | INTEGER | BIGINT | DECIMAL | FLOAT | REAL | DOUBLE

Description

The ALTER TABLE ADD COLUMN statement adds a column to a streaming table. The added column contains a NULL for each row.

Parameters table_name The name of the table where the column is added.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 73 column_name The name of the column that is added.

Examples

The following example adds a column named salary of type BIGINT to streaming table Person.

CREATE TABLE Person2 ( name VARCHAR(30) NOT NULL PRIMARY KEY, address VARCHAR(*) ) WITH TYPE STREAMING ENGINE 'DISK';

ALTER TABLE Person2 ADD COLUMN salary BIGINT;

1.4.3.15 Alter Table Drop Data Source

Detaches an external data source from a table.

Syntax

drop_datasource ::= ALTER TABLE table_name DROP DATASOURCE datasource_name | ALL

Description

The ALTER TABLE DROP DATASOURCE statement detaches a file from a datasource table. Note, that for the statement to take place, a LOAD statement is needed.

Examples

The following statement drops the datasource US1 from the table person:

ALTER TABLE person ADD DATASOURCE AS US1 CSV('/misc/persons_us.csv') SKIP 1 DELIMITED BY ',';

ALTER TABLE person DROP DATASOURCE US1;

Note, that after this, if you try to add US1, it will state that such a datasource already exists. The same behavior can be seen when checking the loaded data - the data would not be removed by an ALTER statement. A LOAD is needed to execute the drop.

SQL Reference for SAP Vora in SAP Data Hub 74 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.4.3.16 Connection Types for DATASOURCE and EXPORT with Connection Manager

If using the Connection Managent application (USING CONNECTION syntax), the datasource_resource is a subpath/file in that connection.

Example: The Connection Managent application is configured and has a connection s3_connection with the correct the credentials and the root path is set to /bucket1/2018/. If there’s a file in /bucket1/2018/ january/customers.csv, we can add this data source with:

ALTER TABLE customers ADD DATASOURCE 'january/customers.csv' USING CONNECTION 's3_connection';

To load other file formats, add the file type before as specified in datasource_format

ALTER TABLE customers ADD DATASOURCE PARQUET ('january/customers.parquet') USING CONNECTION 's3_connection';

To export table tbl into a file /bucket1/2018/export/customers01.csv using the mentioned s3_connection, use:

EXPORT tbl INTO CSV('export/customers01.csv') USING CONNECTION 's3_connection' AS FILE;

 Note

The USING CONNECTION syntax currently only works for ADD DATASOURCE, but not for EXPORT.

1.4.3.17 Connection Types for DATASOURCE and EXPORT without Connection Management

datasource_resource ::= [ HDFS | WEBHDFS | S3 | ADLS | GCS | WASB ] resource_string

HDFS/WEBHDFS, S3, ADL, GCS, WASB If not set, the default connection is of type FILE, so the resource_string is a file path to a local file. resource_string resource_string is a string literal with single quotes, for example, '/data/ myfile.csv.gz'.

If datasource_resource is set but not to FILE, resource_string specifies the configuration for accessing the remote file storage. The resource_string can be extended to contain additional parameters, separated by ampersand (&). For example:

WEBHDFS('Proxy=noproxy&Username=Vora&webhdfs://my.cluster.com/path/to/file.csv')

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 75 This has two parameters:

● Proxy = noproxy ● Username = Vora

The attached URL is webhdfs://my.cluster.com/path/to/file.csv, and the connection type is WEBHDFS.

FILE Connection

To open normal files from the local file system, use the plain path in single quotes, for example:

CREATE TABLE nation_table(i INT) WITH TYPE DATASOURCE;

ALTER TABLE nation_table ADD DATASOURCE '/path/to/nation.csv';

ALTER TABLE nation_table ADD DATASOURCE FILE('/path/to/nation.csv');

Note that you can also explicitly specify that this is a FILE source, but it is not necessary.

HDFS Connection

HDFS('hdfs:///path/to/file.csv')

Here is the host name of the HDFS namenode. This can also include the port, specified with :. If the port is not given, the default HDFS port (8020) is used.

WEBHDFS Connection

You can use WebHDFS over a secure connection (swebhdfs://) or over a normal connection (webhdfs://). You can use the webhdfs prefix or, if you already have an http link, a URL with an http:// or https:// prefix:

WEBHDFS('webhdfs:///path/to/file.csv')

WEBHDFS('http:///v1/webhdfs/path/to/file.csv')

Here is the host name of the WebHDFS server. This can include the port, specified with :. If the port is not given, the default WebHDFS port is used (50070 for http/webhdfs, 50470 for https/swebhdfs).

Additional Parameters

● Proxy: Override default proxy information from the environment. It can also be set to the reserved word noproxy to completely ignore the proxy. ● Username : The user to use when connecting

SQL Reference for SAP Vora in SAP Data Hub 76 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Example

 Sample Code

WEBHDFS('Proxy=noproxy&Username=Vora&webhdfs://my.cluster.com/path/to/ file.csv')

S3 Connection

Amazon S3 buckets are abstracted as folders in the root folder (vora/file names a file inside a bucket named vora). Files can only be placed inside a bucket.

Parameters ● AccessKey (required) ● SecretAccessKey (required) ● Region: The region to connect to. Only buckets in this region are available for operations. This is also the region for all buckets created with this connection. Default: us-east-1 ● Timeout: Network operations timeout (in milliseconds). Default: 3 minutes (180 000) ● Path: The bucket + directory/file in which all operations are performed. The bucket and its directory/file must be separated by a forward slash (/) and must already exist. If set, it must be the last parameter. Default: empty (root)

Example

 Sample Code

S3('AccessKey=AKIAxxxxxxxxxxxxxxx&SecretAccessKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx&Path=mybucket/path/file.csv')

Microsoft Azure Data Lake Storage Connection (ADLS)

Parameters ● ClientId (required) ● ClientSecret (required) ● TenantId (required) ● AccountName (required) ● Path: The file or directory in which all operations are performed (it must already exist). If set, it must be the last parameter. Default: empty (root directory)

Example

ADL('ClientId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx&ClientSecret=xx/ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&TenantId=xxxxxxxxx-xxxx-xxxx-xxxx- xxxxxxxxxxxxx&AccountName=myAccountName')

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 77 Google Cloud Storage (GCS)

To connect to GCS, you need three parameters: Iss, Key, and Project.

They can be found in the JSON private key. To obtain a private key, go to your Google Cloud Platform console and search for Service Accounts. On the Service Accounts page, create a service account if you don't have one yet. Click the Options button and create a JSON private key. A JSON file will be downloaded with the authentication parameters.

Parameters

● Iss (required): It is shown as client_email in the JSON file of your service account. ● Key (required): It is shown as private_key in the JSON file of your service account. You need to remove the initial -----BEGIN PRIVATE KEY----- and final -----END PRIVATE KEY-----. You also need to replace all \\n occurrences with spaces. ● Project (required): It is shown as project_id in the JSON file of your service account. ● Timeout: The period of time in seconds before an operation fails. The default is 180 seconds. ● Proxy: The proxy server address that will be used by the plugin. If you set it to noproxy, the plugin will not go through any proxy server. ● Path: The file or directory in which all operations will be performed (it must already exist). If set, it must be the last parameter. Default: empty (root directory)

Example

 Sample Code

GCS('[email protected]&Key=xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx&Project=xxx-xxxx-xxxx-xxxxx&&Proxy=noproxy&Path=dir/dir')

Windows Azure Storage Blob (WASB)

WASB containers are abstracted as folders in root (eg "vora/file.csv" is a Blob inside a container named "vora"), and forward-slashes ('/') are used for directory hierarchy. It is possible to read data from Block, Append, or Page Blobs.

Parameters

● AccountName (required): storage account name. ● AccountKey (required): access key to authenticate requests to AccountName. ● Host: service endpoint. Default: 'blob.core.windows.net'. ● Protocol: http or https. Default: https. ● Certificate: path in local file system for a CA bundle file. Default: System certificate from OpenSSL. ● Timeout: the time in seconds where a operation will fail, default is 180 seconds. ● Proxy: the proxy server address that's going to be used by the plugin. If you set it to *noproxy*, the plugin will not go through any server proxy. ● Path: The file/directory in which all operations will be performed (must already exist). If set, must be the last parameter. Default: empty (root directory).

SQL Reference for SAP Vora in SAP Data Hub 78 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Example

 Sample Code

WASB('AccountName=xx&AccountKey=xxxxx/xxxxx/ xxxxx&Proxy=noproxy&Path=container/path')

Examples

 Note

For the following examples, a LOAD statement is needed to load the data from the datasources.

The simplest example would be to add a local datasource, using all default options:

CREATE TABLE DS_TABLE(I INT) WITH TYPE DATASOURCE;

ALTER TABLE DS_TABLE ADD DATASOURCE '/tmp/data.csv';

To be able to reference the datasource, a name is given to it:

ALTER TABLE DS_TABLE ADD DATASOURCE AS DS_1 '/tmp/data.csv';

Given a file compressed using gzip, it can be added like:

ALTER TABLE DS_TABLE ADD DATASOURCE AS DS_2 ZIP('/tmp/data.csv.gz');

By default, the format is CSV. So the following statement is equivalent to the one above:

ALTER TABLE DS_TABLE ADD DATASOURCE AS DS_3 CSV(ZIP('/tmp/data.csv.gz'));

Similarly, it should be specified when the format is PARQUET, ORC or AVRO.

Example to load a 2nd column from a parquet file to a specific column from table:

CREATE TABLE PPL_TBL(FIRST_NAME CHAR(50), LAST_NAME CHAR(50), AGE INT, SALARY DOUBLE) WITH TYPE DATASOURCE;

ALTER TABLE PPL_TBL ADD DATASOURCE AS D1 (FIRST_NAME AS $2) PARQUET('/tmp/ users.parquet');

Now, if the 2nd column is actually the last name, both first_name and last_name columns will have the same values.

Switching the last name with the first name:

ALTER TABLE PPL_TBL ADD DATASOURCE AS D2 (FIRST_NAME FROM COLUMN "last_name", LAST_NAME FROM COLUMN "first_name") PARQUET('/tmp/users.parquet');

Ignoring errors for a specific column, using specific default values:

ALTER TABLE PPL_TBL ADD DATASOURCE AS D3 (FIRST_NAME DEFAULT VALUE 'No_Name') PARQUET('/tmp/users.parquet') ON ERROR CONTINUE;

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 79 Different separators for decimal numbers in CSV:

CREATE TABLE dec_tbl(D DOUBLE) WITH TYPE DATASOURCE;

ALTER TABLE dec_tbl ADD DATASOURCE (D DECIMAL SEPARATED BY ';') '/tmp/in.csv';

Input D column after load

123;2 123.2

2;2 2.2

;4 0.4

3;32 3.32

Specifying custom delimiter ';' ('"' is the default string delimiter):

Input:

1;"interesting;;;;";2 3;"aaa";4

5;"bbb";6

CREATE TABLE T_DEL(I INT, C VARCHAR(*), J INT) WITH TYPE DATASOURCE; ALTER TABLE T_DEL ADD DATASOURCE '/tmp/in.csv' DELIMITED BY ';';

SELECT * FROM T_DEL;

I C J

1 interesting;;;; 2

3 aaa 4

5 bbb 6

Example using the escape character:

//input

1,s,111

2 2,$,,2222

The following statement will load "," as c in the second row:

CREATE TABLE ESCAPED(I INT, C CHAR, J INT) WITH TYPE DATASOURCE;

ALTER TABLE ESCAPED ADD DATASOURCE '/tmp/in.csv' DELIMITED BY ',' ESCAPE CHARACTER '$';

LOAD TABLE ESCAPED;

Loading a zipped CSV file from WEBHDFS:

CREATE TABLE zipped_nation(i INT) WITH TYPE DATASOURCE ENGINE 'MEMORY';

ALTER TABLE zipped_nation ADD DATASOURCE ZIP(WEBHDFS('swebhdfs://my.cluster.com/ account/path/nation.txt.zip'));

Loading a Parquet file from HDFS:

CREATE TABLE table1(i INT) WITH TYPE DATASOURCE ENGINE 'MEMORY';

ALTER TABLE table1 ADD DATASOURCE PARQUET(HDFS('hdfs://my.cluster.com/account/ path/table.parquet'));

SQL Reference for SAP Vora in SAP Data Hub 80 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Loading a CSV file from disk with additional options:

CREATE TABLE table2(i INT) WITH TYPE DATASOURCE ENGINE 'MEMORY';

ALTER TABLE table2 ADD DATASOURCE '/path/to/file.csv' DELIMITED BY '|' THOUSANDS SEPARATED BY ' ';

The following statement attaches a file to the datasource table person:

CREATE TABLE person( name NVARCHAR(*), forename NVARCHAR(*), age INTEGER ) WITH TYPE DATASOURCE ENGINE 'MEMORY'; ALTER TABLE person ADD DATASOURCE AS UK ZIP('/misc/persons_uk.csv.zip') SKIP 1 DELIMITED BY '|'; ALTER TABLE person ADD DATASOURCE AS US CSV('/misc/persons_us.csv') SKIP 1 DELIMITED BY ',';

LOAD TABLE person;

1.4.3.18 Create Audit Policy

Creates a new audit policy.

Syntax

create_audit_policy ::= CREATE AUDIT POLICY policy_name AUDITING audit_status audit_actions LEVEL audit_level audit_status ::= SUCCESSFUL | UNSUCCESSFUL | ALL audit_actions ::= system_action_list | target_audit_action_list system_action_list ::= system_action {, system_action } system_action ::= GRANT PRIVILEGE | REVOKE PRIVILEGE | GRANT ROLE | REVOKE ROLE target_audit_action_list ::= target_audit_action_name {, target_audit_action_name } ON audit_object_name {, audit_object_name } target_audit_action_name ::= INSERT | UPDATE | DELETE | SELECT | EXECUTE audit_object_name ::= [schema_name.]schema_object_name

audit_level ::= EMERGENCY | ALERT | CRITICAL | WARNING | INFO

Description

The CREATE AUDIT POLICY statement creates a new audit policy. Only database users with the system privilege AUDIT ADMIN are allowed to create an audit policy. The specified audit policy name must be unique and may not match the name of an existing audit policy.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 81 Parameters policy_name

The name of the audit_policy. If not enclosed by double quotes, all characters of the parameter are stored in uppercase. audit_status This parameter defines whether successful, unsuccessful or all executions of the specified audit actions are audited. For the current release, the audit_status parameter is ignored. audit_object_name Specifies the name of a schema, table, view or stored procedure. The object may or may not exist at the audit policy creation time. The audit policy for a given object name will always be applied while the object exists on the database. For instance, if an object is deleted and then created again, the policy also becomes active again for the recreated object. audit_level

This parameter is ignored, and is only maintained due to compatibility with SAP HANA.

 Note

The schema or schema object must not exist at the creation time of the audit policy. The objects can be created later. Additionally, in case a referred object is deleted and created again, the policy becomes active again for the recreated object.

Examples

The following statement creates the audit policy clients_audit, which applies to INSERT, UPDATE and DELETE actions on the schema object Clients.PersonalInfo:

CREATE AUDIT POLICY clients_audit AUDITING ALL INSERT, UPDATE, DELETE ON Clients.PersonalInfo LEVEL INFO;

The following statement creates the audit policy grants_audit, which applies if any role or privilege is granted:

CREATE AUDIT POLICY "grants_audit" AUDITING SUCCESSFUL GRANT ROLE, GRANT PRIVILEGE LEVEL INFO;

SQL Reference for SAP Vora in SAP Data Hub 82 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.4.3.19 Drop Audit Policy

Deletes an audit policy.

Syntax

drop_audit_policy ::= DROP AUDIT POLICY policy_name

Description

The DROP AUDIT POLICY deletes an audit policy.

Parameters policy_name: Must specify an existing audit policy.

Examples

The following statement drops the audit policy clients_audit.

DROP AUDIT POLICY clients_audit;

1.4.4 Data Query Language (DQL)

Related Information

Select [page 84]

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 83 1.4.4.1 Select

The SELECT statement is used to retrieve information from the database.

Syntax

query_specification ::= SELECT [set_quantifier] select_list table_expression set_quantifier ::= DISTINCT | ALL select_list ::= '*' | select_sublist {, select_sublist}| column_function_expression table_expression ::= from_clause [where_clause] [group_by_clause] [having_clause] select_sublist ::= identifier_chain | value_expression [AS identifier] from_clause ::= FROM table_reference_list where_clause ::= WHERE search_condition group_by_clause ::= GROUP BY grouping_element {',' grouping_element} having_clause ::= HAVING search_condition table_reference_list ::= table_reference {',' table_reference} search_condition ::= value_expression column_function_expression ::= std_aggregation '(' column ')'

std_aggregation ::= SUM | AVG | MIN | MAX | COUNT

Description

A SELECT statement retrieves zero or more rows from one or more database tables or database views.

Parameters set_quantifier DISTINCT returns only distinct (different) values. The default is ALL. select_list '*' specifies to select all the fields avaialable in the table. select_sublist Either specific columns to select (optionally with aliases) or everything identified by identifier_chain. from_clause Specifies the table(s) from which to select. where_clause Used to extract only records that fulfill a specified condition. group_by_clause provides the possibility to group the result set by one or more grouping elements (usually columns), often used with aggregate functions.

SQL Reference for SAP Vora in SAP Data Hub 84 PUBLIC SQL Reference for SAP Vora in SAP Data Hub having_clause Filters results using an aggregate function. grouping_element Specifies a way to group the output. Currently, the following ways are supported:

● column - group by the value of a specific column (may be an alias), e.g. "GROUP BY col1"; ● value_expression - group by a value derived from one/multiple column(s), e.g. "GROUP BY col1 + col2". The specified expression should match exactly an expression from select list. Note: aggregate functions are not allowed, nor aliases to them; ● list of columns - group by a combination of columns, e.g. "GROUP BY col1, col2, col3" - this will take a union of col1, col2, col3; ● grouping sets - similar to previous one, but also allows for more complex combinations, like "GROUP BY GROUPING SETS(A, B, (C, D))" - union of results of grouping by A, by B and by C, D; ● ROLLUP - special form of grouping sets: "GROUP BY ROLLUP(A, B, C)" is equivalent to "GROUP BY GROUPING SETS((A, B, C), (A, B), A, ())"; ● CUBE - special form of grouping sets: "GROUP BY CUBE(A, B, C)" is equivalent to "GROUP BY GROUPING SETS((A,B,C), (A,B), (A,C), (B,C), A, B, C, ())".

SUM Returns the sum of records of a column. The result is of INTEGER type for TINYINT, SMALLINT and INTEGER input; BIGINT for BIGINT input and DECIMAL(38, ) for DECIMAL input. AVG Returns the average of records of a column. The return type is DECIMAL(9, 6) for TINYINT intput, DECIMAL(11, 6) for SMALLINT, DECIMAL(16, 6) for INTEGER, DECIMAL(25, 6) for BIGINT input, or input column type otherwise. MIN Returns the minimal value from all records of a column. Return type is same as input column type. MAX Returns the maximal value from all records of a column. Return type is same as input column type. COUNT Returns the BIGINT number of column records.

Examples

Creating a table and adding values to it:

CREATE TABLE T1(I INT) WITH TYPE STREAMING;

INSERT INTO T1 VALUES (1), (2), (2), (4), (5);

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 85 I

1

2

2

4

5

Selecting only distinct values:

SELECT DISTINCT I FROM T1;

I

1

2

4

5

Creating another table with more columns:

CREATE TABLE T2(I INT, name CHAR(10), d DOUBLE) WITH TYPE STREAMING;

INSERT INTO T2 VALUES (10, 'Frodo', 3.5), (20, 'Bilbo', 2.3), (20, 'Samwise', 1.2), (40, 'Gimli', 232), (50, 'Legolas', 3);

Good guys Score

Frodo 3.5

Bilbo 2.3

Samwise 1.2

Gimli 232

Legolas 3

Selecting an expression:

SELECT name, d + 2 FROM T2;

Name d + 2

Frodo 5.5

Bilbo 4.3

Sawise 3.2

Gimli 234

Legolas 5

SQL Reference for SAP Vora in SAP Data Hub 86 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Filtering based on a condition:

SELECT name FROM T2 WHERE I > 30;

Name

Gimli

Legolas

Counting how many entries have a class "A":

CREATE TABLE T3(I INT, class CHAR) WITH TYPE STREAMING;

INSERT INTO T3 VALUES (10, 'A'), (20, 'B'), (20, 'C'), (40, 'A'), (50, 'B');

SELECT COUNT(i) AS Population, class FROM T3 GROUP BY class;

Population Class

2 A

2 B

1 C

Counting how many entries have class "A" and are available:

CREATE TABLE T4(I INT, class CHAR, available BOOLEAN) WITH TYPE STREAMING;

INSERT INTO T4 VALUES (10, 'A', TRUE), (20, 'B', FALSE), (20, 'C', TRUE), (40, 'A', FALSE), (50, 'B', FALSE);

SELECT COUNT(i) AS Population, class, available FROM T4 GROUP BY class, available;

Population Class Available

1 A False

1 A True

2 B False

1 C True

Dislaying classes that have at least 2 entries:

SELECT COUNT(i), class FROM T3 GROUP BY class HAVING COUNT(i) >= 2;

Count(i) Class

2 A

2 B

Computing the average of a column:

SELECT AVG(I) FROM T4;

Group by a substring of a column:

SELECT SUBSTRING(NAME, 5, 1), SUM(D) FROM T2 GROUP BY SUBSTRING(NAME, 5, 1);

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 87 SUBSTRING(NAME, 5, 1) SUM(D)

i 233.2

l 3

o 5.800000000000001

1.5 SQL Functions and Operators

Table 5:

Engine Category Function Description

Relational Engine Numeric Functions abs(numeric) → numeric Returns the absolute value of a numeric ar­ gument. [page 98]

Relational Engine Numeric Functions acos(numeric) → double Returns the arc-cosine, in radians, of the numeric argument. [page 98]

Relational Engine Numeric Functions asin(numeric) → double Returns the arc-sine, in radians, of the nu­ meric argument. [page 98]

Relational Engine Numeric Functions atan(numeric) → double Returns the arc-tangent, in radians, of the numeric argument. [page 98]

Relational Engine Numeric Functions atan2(numeric, nu­ Returns the arc-tangent, in radians, of the meric) → double ratio of two numbers. [page 98]

Relational Engine Numeric Functions bitand(integer, integer) Performs a bitwise AND operation on the → integer two integer arguments. [page 98]

Relational Engine Numeric Functions bitnot (integer) → integer Performs a bitwise NOT operation on the argument. [page 98]

Relational Engine Numeric Functions bitor (integer, integer) → Performs a bitwise OR operation on the integer two integer arguments. [page 98]

Relational Engine Numeric Functions bitxor (integer, integer) Performs a bitwise XOR operation on the → integer two integer arguments. [page 98]

Relational Engine Numeric Functions ceil (numeric) → numeric Returns the smallest integer that is greater than or equal to the specified value. [page 98]

Relational Engine Numeric Functions cos (numeric) → double Returns the cosine of the angle, in radians, for the specified argument. [page 98]

Relational Engine Numeric Functions cosh (numeric) → double Returns the hyperbolic cosine of the speci­ fied argument. [page 98]

SQL Reference for SAP Vora in SAP Data Hub 88 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Engine Category Function Description

Relational Engine Numeric Functions cot (numeric) → double Returns the cotangent of the angle, in radi­ ans, for the specified argument. [page 98]

Relational Engine Numeric Functions floor (numeric) → nu­ Returns the largest integer that is not meric greater than the specified numeric argu­ [page 98] ment.

Relational Engine Numeric Functions mod (: nu­ Returns the remainder of div­ meric, : nu­ ided by . [page 98] meric) → numeric

Relational Engine Numeric Functions ln (numeric) → double Returns the natural logarithm of the speci­ fied argument. [page 98]

Relational Engine Numeric Functions log (numeric) → double Returns the logarithm of base 10 of the specified number. [page 98]

Relational Engine Numeric Functions log (: numeric, Returns the logarithm of the given base of : numeric) → the specified number. [page 98] double

Relational Engine Numeric Functions power (: nu­ Calculates a specified base number raised meric, : nu­ to the power of a specified argument. [page 98] meric) → double

Relational Engine Numeric Functions round (: nu­ Rounds the specified argument to the meric, : integer) specified number of digits after the deci­ [page 98] → numeric mal point.

Relational Engine Numeric Functions sin (numeric) → double Returns the sine of an angle expressed in radians. [page 98]

Relational Engine Numeric Functions sinh (numeric) → double Returns the hyperbolic sine of the specified argument. [page 98]

Relational Engine Numeric Functions sign (numeric) → integer Returns the sign (-1,0,+1) of the specified numeric argument. [page 98]

Relational Engine Numeric Functions sqrt (numeric) → double Returns the square root of the specified ar­ gument. [page 98]

Relational Engine Numeric Functions tan (numeric) → double Returns the tangent of a specified number, where the argument is an angle expressed [page 98] in radians.

Relational Engine Numeric Functions tanh (numeric) → double Returns the hyperbolic tangent of the specified argument. [page 98]

Relational Engine String Functions [page concat (string,string) → Returns the combined string consisting of 99] string two specified strings.

Relational Engine String Functions [page length (string) → integer Returns the number of characters in a 99] string.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 89 Engine Category Function Description

Relational Engine String Functions [page locate (: Returns the first location of string : string dle> in string . If [, : inte­ is 1, the last location is returned. If is not found, 0 is returned.

Relational Engine String Functions [page lower (string) → string Converts all characters in a string to lower­ 99] case.

Relational Engine String Functions [page ltrim (: string [, Returns a string, trimmed of all leading 99] : string]) spaces. If is specified, ltrim → string removes all the characters contained in this set from the start of string .

Relational Engine String Functions [page replace (: string, specified string and replaces them with an­ : string, other specified string. : string) → string

Relational Engine String Functions [page reverse (string) → string Reverses the characters in a string. 99]

Relational Engine String Functions [page rtrim (: string [, Returns a string, trimmed of all trailing 99] : string]) spaces. If is specified, rtrim → string removes all the characters contained in this set from the end of string .

Relational Engine String Functions [page substring (: string, Returns a substring of starting from 99] : integer within the string. When [, : inte­ is not specified, the entire ger]) → string substring starting from is returned. When is speci­ fied, the returned string consists of characters starting from . If is greater than the length of the remaining part of , then the remaining part is re­ turned without blank padding.

Relational Engine String Functions [page trim ([[LEADING | Returns a string after removing leading and 99] TRAILING | BOTH] trailing spaces. : string FROM] :string) → string

Relational Engine String Functions [page upper (string) → string Converts all characters in a string to upper­ 99] case.

Relational Engine Datetime Functions add_days (date | time­ Computes the specified date or timestamp [page 100] stamp, integer) → date | plus the specified days. timestamp

Relational Engine Datetime Functions add_hours (time | time­ Returns a value of type TIME and TIME­ [page 100] stamp , integer) → time | STAMP, respectively, where increment timestamp hours are added to the given time or time­ stamp.

SQL Reference for SAP Vora in SAP Data Hub 90 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Engine Category Function Description

Relational Engine Datetime Functions add_minutes (time | Adds the specified number of minutes to [page 100] timestamp, integer) → the specified time or timestamp. time | timestamp

Relational Engine Datetime Functions add_months (date | Adds the specified number of months to [page 100] timestamp, integer) → the specified date or timestamp. date | timestamp

Relational Engine Datetime Functions add_seconds (time | Adds the specified number of seconds to [page 100] timestamp, integer) → the specified time or timestamp. time | timestamp

Relational Engine Datetime Functions add_years (date | time­ Adds the specified number of years to the [page 100] stamp, integer) → date | specified date or timestamp. timestamp

Relational Engine Datetime Functions current_date → date Returns the current local system date. [page 100]

Relational Engine Datetime Functions current_time → time Returns the current local system time. [page 100]

Relational Engine Datetime Functions current_timestamp → Returns the current local system time­ [page 100] timestamp stamp.

Relational Engine Datetime Functions datediff ({NANOSEC­ Gives the signed number of the date part [page 100] OND | MICROSECOND | boundaries crossed between the start date MILLISECOND | SEC­ and end date . OND | MINUTE | HOUR}, Note that DATE and TIMESTAMP can not : date | time be compared with TIME. When comparing | timestamp, : date | time | is assumed for the specified DATE. Note timestamp) → integer that when the date part is NANOSECOND, the relational in-memory engine always re­ turns a multiple of 100 and the relational disk engine always returns a multiple of 1000. The reason for this is that times are internally stored up to a precision of 100 nanoseconds in the relational in-memory engine and a precision of 1000 nanosec­ onds in the relational disk engine.

Relational Engine Datetime Functions dayname (date | time­ Returns the weekday in English for the [page 100] stamp) → string specified date or timestamp.

Relational Engine Datetime Functions dayofmonth (date | Returns the day of the month for the speci­ [page 100] timestamp) → integer fied date or timestamp.

Relational Engine Datetime Functions dayofyear (date | time­ Returns an integer representation of the [page 100] stamp) → integer day of the year for the specified date or timestamp.

Relational Engine Datetime Functions days_between (date | Computes the number of days between [page 100] timestamp, date | time­ two dates or timestamps. stamp) → integer

Relational Engine Datetime Functions hour (time | timestamp) Returns an integer representation of the [page 100] → integer hour for the specified time or timestamp. The result is given in 24-hour format.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 91 Engine Category Function Description

Relational Engine Datetime Functions last_day (date | time­ Returns the date of the last day of the [page 100] stamp) → date month that contains the specified date or timestamp.

Relational Engine Datetime Functions minute (time | time­ Returns an integer representation of the [page 100] stamp) → integer minute for the specified time or time­ stamp.

Relational Engine Datetime Functions month (date | time­ Returns the number of the month from the [page 100] stamp) → integer specified date or timestamp.

Relational Engine Datetime Functions monthname (date | Returns the name of the month in English [page 100] timestamp) → string for the specified date or timestamp.

Relational Engine Datetime Functions now () → timestamp Returns the current local system time­ [page 100] stamp.

Relational Engine Datetime Functions quarter (date | time­ Returns the numerical year quarter of the [page 100] stamp) → string specified date or timestamp.

If the date or timestamp stores a date for year 2018, for example, the result depends on the month as follows:

● January, February, March → 2018-Q1 ● April, May, June → 2018-Q2 ● July, August, September → 2018-Q3 ● October, November, December → 2018-Q4

Relational Engine Datetime Functions second (time | time­ Returns a value of the seconds for a given [page 100] stamp) → decimal (9,7) time or timestamp.

Relational Engine Datetime Functions year (date | timestamp) Returns a value of the seconds for a given [page 100] → integer time or timestamp. The relational in-mem­ ory engine takes fractional seconds into account, whereas fractional seconds are ignored for the relational disk engine. For example on the relational in-memory en­ gine, second( TIMESTAMP '2018-01-01 13:30:01.1234567' ) → 1.1234567, but on the relational disk engine, second( TIME­ STAMP '2018-01-01 13:30:01.1234567' ) → 1.0000000.

Relational Engine Datetime Functions week (date | timestamp) Returns the week number of the specified [page 100] → integer date.

Relational Engine Datetime Functions weekday (date | time­ Returns an integer representation for a [page 100] stamp) → integer given date. Return values range from 1 to 7, representing Monday(1) to Sunday(7).

Relational Engine Data Type Conversion cast ( as Converts the expression to the target data Functions [page 102] ) type.

Relational Engine Data Type Conversion to_boolean () → boolean

SQL Reference for SAP Vora in SAP Data Hub 92 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Engine Category Function Description

Relational Engine Data Type Conversion to_bigint () Converts the expression to type BIGINT. Functions [page 102] → bigint

Relational Engine Data Type Conversion to_char (: Converts the specified date, time, or time­ Functions [page 102] date | time | timestamp, stamp to data type CHAR. The format : string) → char must be a constant CHAR or VARCHAR and specifies how to format the supplied value. For a full list of date and time format specifiers, see Date and Time Format Specifiers. The to_char function only sup­ ports the conversion of types DATE, TIME, or TIMESTAMP. Use the cast ( as CHAR(integer)) syntax to convert other types to CHAR and to explicitly specify the length of the resulting CHAR type.

Relational Engine Data Type Conversion to_date(: Converts expressions of type VARCHAR, Functions [page 102] string | date | time­ CHAR, or TIMESTAMP into a value of type stamp[, : DATE. If the input is of type DATE, then the string]) → date input is returned unchanged. If present, format must be a constant CHAR or VAR­ CHAR. If format is omitted, "YYYY-MM-DD" is used as the format. For a full list of date and time format specifiers, see Date and Time Format Specifiers. Timestamps are converted to DATE by dropping the time in­ formation.

Relational Engine Data Type Conversion to_decimal (, : inte­ that has the specified precision and scale. ger, : integer) → and must be constant decimal(,)

Relational Engine Data Type Conversion to_double () → double

Relational Engine Data Type Conversion to_integer () → integer

Relational Engine Data Type Conversion to_real () → Converts a value to data type REAL. Functions [page 102] real

Relational Engine Data Type Conversion to_smallint () → smallint INT.

Relational Engine Data Type Conversion to_time (: Converts expressions of type VARCHAR, Functions [page 102] string | time | timestamp CHAR or TIMESTAMP into a value of type [, : string]) → TIME. If the input is of type TIME, then the time input is returned unchanged. If present, format must be a constant CHAR or VAR­ CHAR. If format is omitted "HH:MI:SS" is used as the format. For a full list of date and time format specifiers, see Date and Time Format Specifiers. TIMESTAMPS are converted to TIME by dropping the date in­ formation.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 93 Engine Category Function Description

Relational Engine Data Type Conversion to_timestamp (: string | date | CHAR, DATE, or TIME into a value of type time | timestamp [, : string]) → time­ STAMP, then the input is returned un­ stamp changed. If present, format must be a con­ stant CHAR or VARCHAR. If format is omit­ ted "YYYY-MM-DD HH:MI:SS.FF7" is used as the format. For a full list of date and time format specifiers, see Date and Time For­ mat Specifiers. If the input is of type TIME, the date part of the timestamp is filled with the current date. If the input is of type DATE, the time part of the timestamp is fil- led with zero.

Relational Engine Data Type Conversion to_tinyint () → tinyint

Relational Engine Data Type Conversion to_varchar ( [, : CHAR. must be a constant CHAR string]) → varchar or VARCHAR. It can only be used if is of type DATE, TIME, or TIME­ STAMP; it specifies how to format the sup­ plied value. For a full list of date and time format specifiers, see Date and Time For­ mat Specifiers. The to_varchar function only supports the conversion of types DATE, TIME, or TIMESTAMP. Use the cast ( as VARCHAR(integer)) to explicitly specify the length of the resulting VARCHAR type.

Relational Engine Hierarchy Functions hierarchy_level(node) → Returns the level of the node in the hierar­ [page 105] bigint chy. The level of a root node is 1.

Relational Engine Hierarchy Functions hierarchy_is_leaf(node) Returns TRUE if the given node is a leaf, [page 105] → boolean that is, does not have children of its own. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_root(node) Returns TRUE if the given node is a root, [page 105] → boolean that is, its parent node is NULL. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_preorder_or­ Returns an ordinal number with the prop­ [page 105] dinal(node) → bigint erty that the preorder ordinal of node n is smaller than the preorder ordinal of node m if and only if n occurs before m in a pre­ order sorting. The exact value of the preor­ der ordinal is not defined and it might not be deterministic.

SQL Reference for SAP Vora in SAP Data Hub 94 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Engine Category Function Description

Relational Engine Hierarchy Functions hierarchy_postorder_or­ Returns an ordinal number with the prop­ [page 105] dinal(node) → bigint erty that the postorder ordinal of node n is smaller than the postorder ordinal of node m if and only if n occurs before m in a post­ order sorting. The exact value of the post­ order ordinal is not defined and it might not be deterministic.

Relational Engine Hierarchy Functions hierar­ Returns TRUE if both arguments refer to [page 105] chy_is_equal(node, the same node in the hierarchy. Returns node) → boolean FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_ances­ Returns TRUE if there is a directed path of [page 105] tor(node, node) → boo­ positive length from the node referred to by lean the first argument to the node referred to by the second argument. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_ances­ Returns TRUE if there is a directed path of [page 105] tor_or_self(node, node) non-negative length from the node referred → boolean to by the first argument to the node refer­ red to by the second argument. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_descend­ Returns TRUE if there is a directed path of [page 105] ant(node, node) → boo­ positive length from the node referred to by lean the second argument to the node referred to by the first argument. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_descend­ Returns TRUE if there is a directed path of [page 105] ant_or_self(node, node) non-negative length from the node referred → boolean to by the second argument to the node re­ ferred to by the first argument. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_pa­ Returns TRUE if there is an edge from the [page 105] rent(node, node) → boo­ node referred to by the first argument to lean the node referred to by the second argu­ ment. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_child(node, Returns TRUE if there is an edge from the [page 105] node) → boolean node referred to by the second argument to the node referred to by the first argu­ ment. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_sib­ Returns TRUE if both arguments refer to [page 105] ling(node, node) → boo­ nodes that share the same parent but are lean not identical. Returns FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_sib­ Returns TRUE if both arguments refer to [page 105] ling_or_self(node, node) nodes that share the same parent. Returns → boolean FALSE otherwise.

Relational Engine Hierarchy Functions hierarchy_is_preced­ Returns TRUE if the node referred to by the [page 105] ing(node, node) → boo­ first argument precedes the node referred lean to by the second argument in a preorder sorting. Returns FALSE otherwise.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 95 Engine Category Function Description

Relational Engine Hierarchy Functions hierarchy_is_follow­ Returns TRUE if the node referred to by the [page 105] ing(node, node) → boo­ first argument follows the node referred to lean by the second argument in a preorder sort­ ing. Returns FALSE otherwise.

Relational Engine Like Predicate [page [NOT] LIKE [ ESCAPE ] → boolean Returns true if can be matched to and false otherwise. If NOT is present, the return value is reversed. The match is case sensitive. , , and are of type CHAR or VARCHAR. If present, must have length 1.

can include the following wild­ cards:

● An underscore ('_') matches any sin­ gle character. ● A percent sign ('%') matches zero or more characters ● If is specified, then is valid if any occurrences of in are followed by either '_', '%', or . In this case, the character that follows a non- escaped character repre­ sents an occurrence of the literal char­ acter in . If both and are of type CHAR, then spaces at the end of both parameters are ignored.

Relational Engine Date and Time Format Date Supported formats: Specifiers [page 107] ● YYYY-MM-DD : Default format ● YYYY/MM/DD, YYYY/MM-DD, YYYY- MM/DD : YYYY from 0001 to 9999, MM from 1 to 12, DD from 1 to 31 ● YYYMMDD : ABAP Data Type, DATS format ● MON : Abbreviated name of month (JAN - DEC) ● MONTH : Name of month (JANUARY - DECEMBER) ● DDD : Day of year (1-366)

SQL Reference for SAP Vora in SAP Data Hub 96 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Engine Category Function Description

Relational Engine Date and Time Format Time Supported formats: Specifiers [page 107] ● HH:MI[:SS][.FF7][AM|PM], HH12:MI[:SS][.FF7][AM|PM], HH24:MI[:SS][.FF7] : HH from 0 to 23, MI from 0 to 59, SS from 0 to 59. If one digit hour, minute, second is specified, 0 is inserted into the value. 9:9:9 is saved as 09:09:09, for exam­ ple. HH12 indicates 12 hour clock, HH24 indicates 24 hour clock. AM or PM can be specified as a suffix to indicate that the time value is be­ fore or after midday. ● FF[1..7] : specifies the number of digits in the fractional second portion. If a digit is not specified, the default value is used. ● SSSSS : seconds past midnight (0-86399)

Relational Engine Date and Time Format Timestamp Supported format: Specifiers [page 107] ● YYYY-MM-DD HH24:MI:SS.FF7 : de­ fault format

Relational Engine Table-Valued Functions HIERARCHY The HIERARCHY table function creates an [page 108] ad-hoc hierarchy.

Related Information

Numeric Functions [page 98] String Functions [page 99] Datetime Functions [page 100] Data Type Conversion Functions [page 102] Hierarchy Functions [page 105] Miscellaneous Functions [page 106] Table-Valued Functions [page 108] Partitioning Tables [page 109]

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 97 1.5.1 Numeric Functions

Numeric functions perform mathematical operations on numerical data types or return numeric information.

abs(numeric) → numeric Returns the absolute value of a numeric argument.

acos(numeric) → double Returns the arc-cosine, in radians, of the numeric argument.

asin(numeric) → double Returns the arc-sine, in radians, of the numeric argument.

atan(numeric) → double Returns the arc-tangent, in radians, of the numeric argument.

atan2 (numeric, numeric) → double Returns the arc-tangent, in radians, of the ratio of two numbers.

bitand(integer, integer) → integer Performs a bitwise AND operation on the two integer arguments.

bitnot (integer) → integer Performs a bitwise NOT operation on the argument.

bitor (integer, integer) → integer Performs a bitwise OR operation on the two integer arguments.

bitxor (integer, integer) → integer Performs a bitwise XOR operation on the two integer arguments.

ceil (numeric) → numeric Returns the smallest integer that is greater than or equal to the specified value.

cos (numeric) → double Returns the cosine of the angle, in radians, for the specified argument.

cosh (numeric) → double Returns the hyperbolic cosine of the specified argument.

cot (numeric) → double Returns the cotangent of the angle, in radians, for the specified argument.

floor (numeric) → numeric Returns the largest integer that is not greater than the specified numeric argument.

mod (: numeric, : Returns the remainder of divided by . numeric) → numeric

ln (numeric) → double Returns the natural logarithm of the specified argument.

log (numeric) → double Returns the logarithm of base 10 of the specified number.

log (: numeric, : Returns the logarithm of the given base of the specified number. numeric) → double

power (: numeric, : Calculates a specified base number raised to the power of a numeric) → double specified argument.

round (: numeric, : Rounds the specified argument to the specified number of digits integer) → numeric after the decimal point.

sin (numeric) → double Returns the sine of an angle expressed in radians.

SQL Reference for SAP Vora in SAP Data Hub 98 PUBLIC SQL Reference for SAP Vora in SAP Data Hub sinh (numeric) → double Returns the hyperbolic sine of the specified argument.

sign (numeric) → integer Returns the sign (-1,0,+1) of the specified numeric argument.

sqrt (numeric) → double Returns the square root of the specified argument.

tan (numeric) → double Returns the tangent of a specified number, where the argument is an angle expressed in radians.

tanh (numeric) → double Returns the hyperbolic tangent of the specified argument.

1.5.2 String Functions

String functions perform extraction and manipulation on strings, or return information about strings.

concat (string,string) → string Returns the combined string consisting of two specified strings.

length (string) → integer Returns the number of characters in a string.

locate (: string, Returns the first location of string in string . If : string [, is a positive integer, or 0, or not specified, then the : integer]) → matching direction proceeds from left to right. If is integer negative, then matching starts at the end of and proceeds in the reverse direction (right to left).

Examples:

● locate( 'abca', 'a' ) → 1 ● locate( 'abca', 'a', 2 ) → 4 ● locate( 'abca', 'd' ) → 0 ● locate( 'abca', 'a', -1 ) → 4 ● locate( 'abca', 'a', -2 ) → 1

lower (string) → string Converts all characters in a string to lowercase.

ltrim (: string [, Returns a string, trimmed of all leading spaces. If is : string]) → string specified, ltrim removes all the characters contained in this set from the start of string .

replace (: string, Searches a string for all occurrences of a specified string and replaces : string, them with another specified string. : string) → string

reverse (string) → string Reverses the characters in a string.

rtrim (: string [, Returns a string, trimmed of all trailing spaces. If is : string]) → string specified, rtrim removes all the characters contained in this set from the end of string .

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 99 substring (: string, Returns a substring of starting from within : integer [, the string. When is not specified, the entire substring : integer]) → starting from is returned. When string is specified, the returned string consists of characters starting from . If is greater than the length of the remaining part of , then the remaining part is returned without blank padding.

trim ([[LEADING | TRAILING | Returns a string after removing leading and trailing spaces. BOTH] : string FROM] :string) → string

upper (string) → string Converts all characters in a string to uppercase.

1.5.3 Datetime Functions

Date and time functions perform operations on date and time data types or return date or time information.

add_days (date | timestamp, integer) Computes the specified date or timestamp plus the specified days. → date | timestamp

add_hours (time | timestamp , Returns a value of type TIME and TIMESTAMP, respectively, where integer) → time | timestamp increment hours are added to the given time or timestamp.

add_minutes (time | timestamp, Adds the specified number of minutes to the specified time or integer) → time | timestamp timestamp.

add_months (date | timestamp, Adds the specified number of months to the specified date or integer) → date | timestamp timestamp.

add_seconds (time | timestamp, Adds the specified number of seconds to the specified time or integer) → time | timestamp timestamp.

add_years (date | timestamp, integer) Adds the specified number of years to the specified date or → date | timestamp timestamp.

current_date → date Returns the current local system date.

current_time → time Returns the current local system time.

current_timestamp → timestamp Returns the current local system timestamp.

datediff ({NANOSECOND | Gives the signed number of the date part boundaries crossed between MICROSECOND | MILLISECOND | the start date and end date . Note that SECOND | MINUTE | HOUR}, DATE and TIMESTAMP can not be compared with TIME. When : date | time | timestamp, comparing DATE with TIMESTAMP, the time 00:00:00 is assumed for : date | time | the specified DATE. Note that when the date part is NANOSECOND, timestamp) → integer the relational in-memory engine always returns a multiple of 100 and

SQL Reference for SAP Vora in SAP Data Hub 100 PUBLIC SQL Reference for SAP Vora in SAP Data Hub the relational disk engine always returns a multiple of 1000. The reason for this is that times are internally stored up to a precision of 100 nanoseconds in the relational in-memory engine and a precision of 1000 nanoseconds in the relational disk engine.

dayname (date | timestamp) → string Returns the weekday in English for the specified date or timestamp.

dayofmonth (date | timestamp) → Returns the day of the month for the specified date or timestamp. integer

dayofyear (date | timestamp) → Returns an integer representation of the day of the year for the integer specified date or timestamp.

days_between (date | timestamp, Computes the number of days between two dates or timestamps. date | timestamp) → integer

hour (time | timestamp) → integer Returns an integer representation of the hour for the specified time or timestamp. The result is given in 24-hour format.

last_day (date | timestamp) → date Returns the date of the last day of the month that contains the specified date or timestamp.

minute (time | timestamp) → integer Returns an integer representation of the minute for the specified time or timestamp.

month (date | timestamp) → integer Returns the number of the month from the specified date or timestamp.

monthname (date | timestamp) → Returns the name of the month in English for the specified date or string timestamp.

now () → timestamp Returns the current local system timestamp.

quarter (date | timestamp) → string Returns the numerical year quarter of the specified date or timestamp.

If the date or timestamp stores a date for year 2018, for example, the result depends on the month as follows:

● January, February, March → 2018-Q1 ● April, May, June → 2018-Q2 ● July, August, September → 2018-Q3 ● October, November, December → 2018-Q4

second (time | timestamp) → decimal Returns a value of the seconds for a given time or timestamp. (9,7)

year (date | timestamp) → integer Returns a value of the seconds for a given time or timestamp. The relational in-memory engine takes fractional seconds into account, whereas fractional seconds are ignored for the relational disk engine. For example on the relational in-memory engine, second( TIMESTAMP '2018-01-01 13:30:01.1234567' ) → 1.1234567, but on the relational

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 101 disk engine, second( TIMESTAMP '2018-01-01 13:30:01.1234567' ) → 1.0000000.

week (date | timestamp) → integer Returns the week number of the specified date.

weekday (date | timestamp) → integer Returns an integer representation for a given date. Return values range from 1 to 7, representing Monday(1) to Sunday(7).

1.5.4 Data Type Conversion Functions

Data type conversion functions convert data from one data type to another data type.

cast ( as ) Converts the expression to the target data type.

::=

BOOLEAN | TINYINT | SMALLINT | BIGINT | DECIMAL | REAL | DOUBLE | CHAR | VARCHAR | DATE | TIMESTAMP | TIME

| INTERVAL

to_boolean () → Converts the expression to type BOOLEAN. boolean

to_bigint () → bigint Converts the expression to type BIGINT.

to_char (: date | time | Converts the specified date, time, or timestamp to data type CHAR. timestamp, : string) → char The format must be a constant CHAR or VARCHAR and specifies how to format the supplied value. For a full list of date and time format specifiers, see Date and Time Format Specifiers. The to_char function only supports the conversion of types DATE, TIME, or TIMESTAMP. Use the cast ( as CHAR(integer)) syntax to convert other types to CHAR and to explicitly specify the length of the resulting CHAR type.

to_date(: string | date | Converts expressions of type VARCHAR, CHAR, or TIMESTAMP into a timestamp[, : string]) → value of type DATE. If the input is of type DATE, then the input is date returned unchanged. If present, format must be a constant CHAR or VARCHAR. If format is omitted, "YYYY-MM-DD" is used as the format. For a full list of date and time format specifiers, see Date and Time Format Specifiers. Timestamps are converted to DATE by dropping the time information.

SQL Reference for SAP Vora in SAP Data Hub 102 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Examples of correct use:

● TO_DATE('2010-05-13') → 2010-05-13 ● TO_DATE('2010-05-13', 'YYYY-MM-DD') → 2010-05-13 ● TO_DATE('February 28', 'MONTH DD') → 0001-02-28 ● TO_DATE('135/09', 'DDD/YY') → 2009-05-15 ● TO_DATE('14 8','YY MM') → 2014-08-01 ● TO_DATE('2008 FEB 29', 'YYYY MON DD') → 2008-02-29 ● TO_DATE('2008 366', 'YYYY DDD') → 2008-12-31 ● TO_DATE('08 03 24', 'YY MM DD') → 2008-03-24 ● TO_DATE('08 03 24', 'YYYY MM DD') → 0008-03-24 ● TO_DATE(TO_TIMESTAMP('2015-02-04 11:44:35.1234')) → 2015-02-04

Examples of incorrect use:

● TO_DATE('2010-05-13-MAY', 'YYYY-MM-DD-MON') (invalid format) ● TO_DATE('February 28 143', 'MONTH DD DDD') (invalid format) ● TO_DATE('135/09', 'DDD-YY') (expression does not match format) ● TO_DATE('14 8 20', 'YY MM') (expression does not match format) ● TO_DATE('14 0008','YY MM') (number of digits of month exceeds 2) ● TO_DATE('2010-05-32', 'YYYY-MM-DD') (invalid date) ● TO_DATE('2009-02-29', 'YYYY-MM-DD') (invalid date)

to_decimal (, Converts a value to data type DECIMAL that has the specified : integer, : precision and scale. and must be constant integer) → literals. decimal(,)

to_double () → double Converts the expression to type DOUBLE.

to_integer () → integer Converts the expression to type INTEGER.

to_real () → real Converts a value to data type REAL.

to_smallint () → Converts the expression to type SMALLINT. smallint

to_time (: string | time | Converts expressions of type VARCHAR, CHAR or TIMESTAMP into a timestamp [, : string]) → value of type TIME. If the input is of type TIME, then the input is time returned unchanged. If present, format must be a constant CHAR or VARCHAR. If format is omitted "HH:MI:SS" is used as the format. For a full list of date and time format specifiers, see Date and Time Format Specifiers. TIMESTAMPS are converted to TIME by dropping the date information.

Examples of correct use:

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 103 ● TO_TIME('11:12:13') → 11:12:13.0000000 ● TO_TIME('11-12-13', 'HH-MI-SS') → 11:12:13.0000000 ● TO_TIME('11:12', 'HH24:MI') → 11:12:00.0000000 ● TO_TIME('3:15 PM') → 15:15:00.0000000 ● TO_TIME('07:12:32 AM') → 07:12:32.0000000 ● TO_TIME('15:16:17.0234', 'HH:MI:SS.FF4') → 15:16:17.0234000 ● TO_TIME(TO_TIMESTAMP('2015-02-04 11:44:35.1234')) → 11:44:35.1234

Examples of incorrect use:

● TO_TIME('14:13', 'HH:MI:SS') (expression does not match format) ● TO_TIME('24:13', 'HH:MI') (invalid time)

to_timestamp (: string | Converts expressions of type VARCHAR, CHAR, DATE, or TIME into a date | time | timestamp [, : value of type TIMESTAMP. If the input is of type TIMESTAMP, then the string]) → timestamp input is returned unchanged. If present, format must be a constant CHAR or VARCHAR. If format is omitted "YYYY-MM-DD HH:MI:SS.FF7" is used as the format. For a full list of date and time format specifiers, see Date and Time Format Specifiers. If the input is of type TIME, the date part of the timestamp is filled with the current date. If the input is of type DATE, the time part of the timestamp is filled with zero.

Examples of correct use:

● TO_TIMESTAMP('2015-02-04 11:44:35.1234') → 2015-02-04 11:44:35.1234000 ● TO_TIMESTAMP('1990-200 12345.01', 'YYYY-DDD SSSSS.FF2') → 1990-07-19 03:25:45.0100000 ● TO_TIMESTAMP('1954-03-02 2:42:21.7654321 pm') → 1954-03-02 14:42:21.7654321 ● TO_TIMESTAMP(TO_DATE('2010-05-13')) → 2010-05-13 00:00:00.0000000

Examples of incorrect use:

● TO_TIMESTAMP(TO_TIME\('11:12:13')) (time cannot be cast to timestamp) ● TO_TIMESTAMP(' ', ' ') (invalid format) ● TO_TIMESTAMP('2015:02:04 10-38-15', 'YYYY-MM-DD HH:MI:SS') (expression does not match format) ● TO_TIMESTAMP('2015-02-04', 'YYYY-MM-DD HH24:MI:SS.FF6' (expression does not match format; no time given)

to_tinyint () → tinyint Converts the expression to type TINYINT.

to_varchar ( [, Converts a given value to data type VARCHAR. must be a : string]) → varchar constant CHAR or VARCHAR. It can only be used if is of type DATE, TIME, or TIMESTAMP; it specifies how to format the supplied value. For a full list of date and time format specifiers, see

SQL Reference for SAP Vora in SAP Data Hub 104 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Date and Time Format Specifiers. The to_varchar function only supports the conversion of types DATE, TIME, or TIMESTAMP. Use the cast ( as VARCHAR(integer)) to explicitly specify the length of the resulting VARCHAR type.

1.5.5 Hierarchy Functions

Hierarchy functions allow you to work with hierarchical data structures.

hierarchy_level(node) → bigint Returns the level of the node in the hierarchy. The level of a root node is 1.

hierarchy_is_leaf(node) → boolean Returns TRUE if the given node is a leaf, that is, does not have children of its own. Returns FALSE otherwise.

hierarchy_is_root(node) → boolean Returns TRUE if the given node is a root, that is, its parent node is NULL. Returns FALSE otherwise.

hierarchy_preorder_ordinal(node) → bigint Returns an ordinal number with the property that the preorder ordinal of node n is smaller than the preorder ordinal of node m if and only if n occurs before m in a preorder sorting. The exact value of the preorder ordinal is not defined and it might not be deterministic.

hierarchy_postorder_ordinal(node) → bigint Returns an ordinal number with the property that the postorder ordinal of node n is smaller than the postorder ordinal of node m if and only if n occurs before m in a postorder sorting. The exact value of the postorder ordinal is not defined and it might not be deterministic.

hierarchy_is_equal(node, node) → boolean Returns TRUE if both arguments refer to the same node in the hierarchy. Returns FALSE otherwise.

hierarchy_is_ancestor(node, node) → boolean Returns TRUE if there is a directed path of positive length from the node referred to by the first argument to the node referred to by the second argument. Returns FALSE otherwise.

hierarchy_is_ancestor_or_self(node, node) → Returns TRUE if there is a directed path of non-negative boolean length from the node referred to by the first argument to the node referred to by the second argument. Returns FALSE otherwise.

hierarchy_is_descendant(node, node) → Returns TRUE if there is a directed path of positive length boolean from the node referred to by the second argument to the node referred to by the first argument. Returns FALSE otherwise.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 105 hierarchy_is_descendant_or_self(node, node) Returns TRUE if there is a directed path of non-negative → boolean length from the node referred to by the second argument to the node referred to by the first argument. Returns FALSE otherwise.

hierarchy_is_parent(node, node) → boolean Returns TRUE if there is an edge from the node referred to by the first argument to the node referred to by the second argument. Returns FALSE otherwise.

hierarchy_is_child(node, node) → boolean Returns TRUE if there is an edge from the node referred to by the second argument to the node referred to by the first argument. Returns FALSE otherwise.

hierarchy_is_sibling(node, node) → boolean Returns TRUE if both arguments refer to nodes that share the same parent but are not identical. Returns FALSE otherwise.

hierarchy_is_sibling_or_self(node, node) → Returns TRUE if both arguments refer to nodes that share the boolean same parent. Returns FALSE otherwise.

hierarchy_is_preceding(node, node) → Returns TRUE if the node referred to by the first argument boolean precedes the node referred to by the second argument in a preorder sorting. Returns FALSE otherwise.

hierarchy_is_following(node, node) → boolean Returns TRUE if the node referred to by the first argument follows the node referred to by the second argument in a preorder sorting. Returns FALSE otherwise.

1.5.6 Miscellaneous Functions

SAP Vora also supports functions that return system values and perform various operations on values, expressions, and return values of other functions.

coalesce (, Returns the first non-NULL expression from a list. The result is NULL if all the , ...) expressions are NULL.

nullif (, Compares both expressions. If both expressions are equal, NULL is returned. ) Otherwise, is returned.

Related Information

Like Predicate [page 107] Date and Time Format Specifiers [page 107]

SQL Reference for SAP Vora in SAP Data Hub 106 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.5.6.1 Like Predicate

Performs a comparison to see if a character string matches a specified pattern.

[NOT] Returns true if can be matched to and false otherwise. If NOT is present, LIKE the return value is reversed. The match is case sensitive. , , and [ ESCAPE are of type CHAR or VARCHAR. If present, must have length 1. ] → boolean can include the following wildcards:

● An underscore ('_') matches any single character. ● A percent sign ('%') matches zero or more characters. ● If is specified, then is valid if any occurrences of in are followed by either '_', '%', or . In this case, the character that follows a non-escaped character represents an occurrence of the literal character in . If both and are of type CHAR, then spaces at the end of both parameters are ignored. Examples: ○ 'Hello' LIKE 'Hello' → true ○ 'Hello' LIKE 'Yellow' → false ○ 'Hello' LIKE 'hello' → false ○ 'Hello' LIKE '' → false ○ '' LIKE '' → true ○ 'Hello' LIKE '_ello' → true ○ 'Hello World' LIKE 'Hello%' → true ○ 'Dr. John Smith' LIKE '%John%' → true ○ 'Dr. John Smith' LIKE '%John%' ESCAPE '#' → true ○ 'Dr. John Smith' LIKE '%John#%' ESCAPE '#' → false ○ 'Dr. John%' LIKE '%John#%' ESCAPE '#' → true ○ 'Dr. John% Smith' LIKE '%John_%' ESCAPE '_' → false ○ 'Dr. John% Smith' LIKE '%%John%%' ESCAPE '%' → false ○ 'Hello World!' LIKE '%World!!' ESCAPE '!' → true ○ 'Hello World!' LIKE '%World!' ESCAPE '!' → Invalid escape sequence ○ 'Hello ' LIKE 'Hello' → true (if parameters of type CHAR) ○ 'Hello' LIKE 'H% _ %' → true (if parameters of type CHAR)

1.5.6.2 Date and Time Format Specifiers

Supported formats for Date:

● YYYY-MM-DD : Default format ● YYYY/MM/DD, YYYY/MM-DD, YYYY-MM/DD : YYYY from 0001 to 9999, MM from 1 to 12, DD from 1 to 31 ● YYYMMDD : ABAP Data Type, DATS format ● MON : Abbreviated name of month (JAN - DEC)

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 107 ● MONTH : Name of month (JANUARY - DECEMBER) ● DDD : Day of year (1-366)

Supported formats for Time:

● HH:MI[:SS][.FF7][AM|PM], HH12:MI[:SS][.FF7][AM|PM], HH24:MI[:SS][.FF7] : HH from 0 to 23, MI from 0 to 59, SS from 0 to 59. If one digit hour, minute, second is specified, 0 is inserted into the value. 9:9:9 is saved as 09:09:09, for example. HH12 indicates 12 hour clock, HH24 indicates 24 hour clock. AM or PM can be specified as a suffix to indicate that the time value is before or after midday. ● FF[1..7] : specifies the number of digits in the fractional second portion. If a digit is not specified, the default value is used. ● SSSSS : seconds past midnight (0-86399)

Supported formats for Timestamp:

● YYYY-MM-DD HH24:MI:SS.FF7 : default format

1.5.7 Table-Valued Functions

Table-valued functions are functions that take logical plans as their input and return a table as their output.

HIERARCHY

The HIERARCHY table function creates an ad-hoc hierarchy.

hierarchy_table_function ::= HIERARCHY '(' hierarchy_spec SET node_column_identifier ')' hierarchy_spec ::= USING table_primary [AS] correlation_name edges_clause [hierarchy_spec_options] correlation_name ::= identifier edges_clause ::= JOIN PRIOR prior_correlation_name join_condition hierarchy_spec_options ::= [[START WHERE search_condition] siblings_order_clause] cycle_options prior_correlation_name ::= identifier join_condition ::= ON search_condition siblings_order_clause ::= ORDER SIBLINGS BY sort_specification_list cycle_options ::= CYCLE RESTRICT | CYCLE PRESERVE | NO CYCLE

sort_specification_list ::= value_expression [ASC|DESC] [NULLS FIRST|LAST]

 Note

Node type and hierarchical functions are currently supported only by the in-memory engine.

The following rules apply:

● The output of the table function is a table containing all columns from the table in the USING clause in the as well as one additional column of type NODE. ● The SET construct allows you to specify the name of a generated column of data type NODE representing the hierarchy nodes.

SQL Reference for SAP Vora in SAP Data Hub 108 PUBLIC SQL Reference for SAP Vora in SAP Data Hub ● The matches two rows and creates an edge between the two nodes corresponding to these two rows. ● The set of edges defined in this way forms a graph. If this graph is not a tree, the evaluation of the HIERARCHY function will fail. ● The must refer to two columns; the left one to the left table and the right one to the right table.

The optional determines the order in which the children of a node are enumerated. If the is not given, the children will be enumerated in arbitrary order, which implies that the pre and post order sorting of all the nodes is arbitrary as well. Note that the elements of the of the will and must refer to the left join table.

The following example creates a NODE column Node for table HT. The roots are all nodes that have no PredId entry (IS NULL):

 Sample Code

CREATE TABLE HT(ID INT, PREDID INT, ORD INT) WITH TYPE DATASOURCE ENGINE 'MEMORY';

SELECT * FROM HIERARCHY(USING HT U JOIN PRIOR V ON (U.PREDID = V.ID) ORDER SIBLINGS BY U.ORD DESC NULLS FIRST NO CYCLE SET NODE) H;

1.5.8 Partitioning Tables

Tables created with com.sap.spark.engines.relational, com.sap.spark.engines.disk, and com.sap.spark.engines are not automatically partitioned, which means that they are not, by default, distributed over all available nodes in the landscape. Unless partitioning is applied, they are always assigned to a single host in the cluster.

To partition tables, you use partition functions and partition schemes. Partition functions allow you to define how tables should be partitioned, while partition schemes are derived from partition functions and are used to apply the partition functions to the tables.

Related Information

Partition Function [page 110] Partition Scheme [page 111] Engine Compatibility Overview [page 112]

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 109 1.5.8.1 Partition Function

A partition function allows you to define how the partitions of a table are created. The supported partition function types are range partitioning, and hash partitioning.

You can create a partition function using the command Create Partition Function [page 57]. The general syntax is shown below:

Syntax

create_pf ::= CREATE PARTITION FUNCTION [schema_name'.']pf_name ( pf_parameter_list ) AS pf_def_list_auto pf_def_list_auto ::= (pf_definition_list ',' AUTO | (pf_definition_list | AUTO)) pf_parameter_list ::= column_name data_type {, pf_parameter_list} pf_definition_list ::= pf_definition { pf_definition_list } pf_definition ::= pf_range | pf_hash | pf_interval pf_range ::= RANGE ['(' identifier_chain ')'] boundary_def pf_hash ::= HASH ['(' identifier_chain { , identifier_chain } ')'] [MIN PARTITIONS unsigned_integer] [PARTITIONS unsigned_integer] [AS identifier] pf_interval ::= INTERVAL '(' identifier_chain ')' [ '-'|'+' ] interval_string_literal interval_qualifier boundary_def ::= BOUNDARIES '(' [value_expression { , value_expression }] ')' identifier_chain ::= identifier {'.' identifier} interval_qualifier ::= ( datetime_field [ '(' unsigned_integer ')' ] TO end_field ) | end_field end_field ::= datetime_field | SECOND'('unsigned_integer')' ]

datetime_field ::= (DAY|HOUR|MINUTE)

The interval for pf_interval must comply with the following rules:

● Duration must be more than 60 seconds

The following are examples of valid intervals: '15' minutes or '12 2' day to hour

The partition function determines how many partitions are created. Since each partition is placed on one host, you should ensure that the number of partitions is equal to or greater than the number of hosts over which you want to distribute the table.

For example, if you have 100 nodes and want to distribute a table over all of them, you should create a partition function that results in at least 100 partitions. For range partitioning, you should define at least 99 boundaries (number of boundaries equal to or greater than n - 1, where n is the target number of nodes). For hash partitioning, you should specify 100 as the minimum number of partitions (minimum partition number equal to the target number of nodes).

Related Information

RANGE Partitioning [page 111] HASH Partitioning [page 111]

SQL Reference for SAP Vora in SAP Data Hub 110 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.5.8.1.1 RANGE Partitioning

Range partitioning allows you to define certain values of a specified column as the boundaries for dividing the data into separate partitions.

For example, given a value range from [0..10), you could specify the values 3 and 6 to create 3 partitions. The first partition would include the values [0..3), the second partition the values [3..6), and the third partition the values [6..10). The definition of a minimum number of partitions and a maximum number of partitions gives the system the flexibility to create further partitions not specified as boundaries. It is important that the maximum number of partitions is not smaller than the number of boundaries + 1.

 Sample Code

CREATE PARTITION FUNCTION PF1 ( X INT )

AS RANGE BOUNDARIES( 2, 4 )

MIN PARTITIONS 3;

1.5.8.1.2 HASH Partitioning

Using HASH partitioning, the values of the specified columns are hashed and added to a partition based on their hash values.

You have to specify the number of partitions used while creating the partition function.

 Sample Code

CREATE PARTITION FUNCTION PF1 ( X INTEGER ) AS HASH(X)

PARTITIONS 5;

1.5.8.2 Partition Scheme

Use a partition scheme to apply and instantiate a partition function.

First create a partition scheme using the following syntax:

::=

CREATE PARTITION SCHEME ::=

USING

 Sample Code

CREATE PARTITION SCHEME PS1 USING PF1;

Then apply the partition scheme as part of the CREATE table statement by simply adding the PARTITION BY clause to the end of it. The PARTITION BY clause contains a reference to the respective partition scheme. In

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 111 addition, the partition scheme and partition function are instantiated by providing the concrete partitioning columns as function parameters to the partition scheme. The syntax is as follows:

::=

PARTITION BY '('')'

 Sample Code

CREATE TABLE ExampleTable (

key1 integer, val1 integer

) TYPE DATASOURCE PARTITION BY PS1(key1);

1.5.8.3 Engine Compatibility Overview

The individual SAP Vora engines support the partition function types as shown below.

Engine RANGE HASH

Files Engine - -

Disk Engine x x

Relational In-Memory Engine x x

1.6 System Views

System views provide information about the SAP Vora system, such as which tables it contains. System views have a fixed schema and can be used to programmatically get schema information about other tables.

Prerequisites

At least one relational in-memory engine needs to be available in the cluster to execute queries on system views.

Overview

System views are located in the SYS schema of each database and provide information about that database only. For example, the SYS.SCHEMAS view shows all schemas for the specific database in which it is located.

The contents of the system views are versioned and directly correspond to a version of the database catalog. Therefore, concurrent queries of system tables might get different results if there is a concurrent modification of the database catalog.

SQL Reference for SAP Vora in SAP Data Hub 112 PUBLIC SQL Reference for SAP Vora in SAP Data Hub  Note

System views are implemented as table views on internal system tables. Those internal system tables have the name prefix INTERNAL and should never be used directly because they will change in future versions.

 Caution

The SYS schema should be considered reserved; you should not attempt to modify it even in the absence of system views. Similarly, modification of any object in the SYS schema is prohibited.

In future versions of SAP Vora, the schemas of system views might change. We recommend that your use of system views does not rely on the number of columns in system views, nor the number of views or tables in the SYS schema.

Identifiers

Note the following about database object identifiers used in system views:

● When selecting database objects from a system view, identifiers can be converted to upper case. ● Object IDs are unique within an SAP Vora installation.

Table 6:

System View Description

SYS.SCHEMAS [page 116] Contains information about all schemas in the current database. Note that schemas that do not contain any tables occur in the SYS.SCHEMAS table but not in the SYS.TABLES table.

SYS.TABLES [page 115] Contains information about all tables in the current database.

SYS.TABLE_COLUMNS [page 116] Contains information about all columns of all tables in the current database.

Contains information about all series key columns in the current database.

SYS.VIEWS [page 117] Contains information about views.

SYS.CONSTRAINTS [page 117] Contains information about all constraints in the current database.

SYS.MATERIALIZED_VIEWS [page 118] Contains information about materialized views

SYS.MATERIALIZED_VIEW_COLUMNS Contains information about all columns of materialized views in the current [page 118] database.

SYS.SYNONYMS [page 119] Contains information about synonyms.

SYS.DUMMY [page 120] Contains dummy information. It has only one fixed row.

SYS.VORA_DATABASE [page 120] Contains information about the instance of the current Vora database.

SYS.VORA_STATISTICS [page 131] Contains statistics about all tables in the current database.

SYS.M_DATABASE [page 120] Contains HANA-compatible information about the instance of the current Vora database.

SYS.VORA_CAPABILITIES [page 121] Contains information about the HANA capabilities supported by the current database.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 113 System View Description

SYS.VORA_FUNCTIONS [page 121] Contains information about SQL functions available in the current database.

SYS.VORA_TABLES [page 122] Contains information about all tables in the current database, including Vora- specific information.

SYS.VORA_TABLE_COLUMNS [page 122] Contains information about all columns of all tables in the current database, including Vora-specific information.

SYS.VORA_DATASOURCES [page 123] Contains information about all the table datasources in the current data­ base.

SYS.VORA_PARTITION_SCHEMES [page Contains information about all partition schemes in the current database, in­ 124] cluding Vora-specific information.

SYS.VORA_PARTITION_FUNCTIONS [page Contains information about all partition functions in the current database, 124] including Vora-specific information.

SYS.VORA_PARTITION_PARAMETERS [page Contains information about all partition parameters in the current database, 125] including Vora-specific information.

SYS.VORA_PARTITION_DEFINITIONS [page Contains information about all partition definitions in the current database, 125] including Vora-specific information.

SYS.OBJECTS [page 126] Contains information about all objects in the current database.

SYS.OBJECT_VERSIONS [page 126] Contains information about object versions in the current database.

SYS.OBJECT_DEPENDENCIES [page 127] Contains information about dependencies of views and materialized views in the current database.

SYS.ROLES [page 128] Contains information about all roles in the current database.

SYS.USERS [page 128] Contains information about all users in the current database.

SYS.GRANTED_ROLES [page 129] Contains information about all granted roles in the current database.

SYS.GRANTED_PRIVILEGES [page 129] Contains information about all granted privileges in the current database.

SYS.AUDIT_POLICIES [page 130] Contains information about all auditlog policies created in the current data­ base.

SYS.VORA_SERIES_TABLES [page 131] Contains information about all timeseries tables in the database.

SYS.SERIES_KEY_COLUMNS [page 132] Contains information about key columns in timeseries tables in the database

SYS.VORA_DATASOURCE_FILES [page 132] Contains information about the files connected to vora datasources.

Related Information

SYS.TABLES [page 115] SYS.SCHEMAS [page 116] SYS.TABLE_COLUMNS [page 116] SYS.VIEWS [page 117] SYS.CONSTRAINTS [page 117] SYS.MATERIALIZED_VIEWS [page 118] SYS.MATERIALIZED_VIEW_COLUMNS [page 118] SYS.SYNONYMS [page 119]

SQL Reference for SAP Vora in SAP Data Hub 114 PUBLIC SQL Reference for SAP Vora in SAP Data Hub SYS.DUMMY [page 120] SYS.VORA_DATABASE [page 120] SYS.M_DATABASE [page 120] SYS.VORA_CAPABILITIES [page 121] SYS.VORA_FUNCTIONS [page 121] SYS.VORA_TABLES [page 122] SYS.VORA_TABLE_COLUMNS [page 122] SYS.VORA_DATASOURCES [page 123] SYS.VORA_PARTITION_SCHEMES [page 124] SYS.VORA_PARTITION_FUNCTIONS [page 124] SYS.VORA_PARTITION_PARAMETERS [page 125] SYS.VORA_PARTITION_DEFINITIONS [page 125] SYS.OBJECTS [page 126] SYS.OBJECT_VERSIONS [page 126] SYS.OBJECT_DEPENDENCIES [page 127] SYS.ROLES [page 128] SYS.USERS [page 128] SYS.GRANTED_ROLES [page 129] SYS.GRANTED_PRIVILEGES [page 129] SYS.AUDIT_POLICIES [page 130] SYS.VORA_STATISTICS [page 131] SYS.VORA_SERIES_TABLES [page 131] SYS.SERIES_KEY_COLUMNS [page 132] SYS.VORA_DATASOURCE_FILES [page 132]

1.6.1 SYS.TABLES

SYS.TABLES contains information about all tables in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

TABLE_OID bigint Object ID of the table

TABLE_TYPE varchar(16) Table type: IN-MEMORY or DISK

HAS_PRIMARY_KEY varchar(5) TRUE if the table has a primary key, otherwise FALSE

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 115 1.6.2 SYS.SCHEMAS

SYS.SCHEMAS contains information about all schemas in the current database. Note that schemas that do not contain any tables occur in the SYS.SCHEMAS table but not in the SYS.TABLES table.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

SCHEMA_OID bigint Object ID of the schema

1.6.3 SYS.TABLE_COLUMNS

SYS.TABLE_COLUMNS contains information about all columns of all tables in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

TABLE_OID bigint Object ID of the table

COLUMN_NAME varchar(256) Name of the column

POSITION integer Ordinal position of the column in a re­ cord

COLUMN_ID bigint Object ID of the column

DATA_TYPE_NAME varchar(256) String-representation of the SQL type of the column; content may change in future versions

LENGTH integer The max number of chars for CHAR types, number of max digits in decimal format for numeric types

SCALE integer The numeric types: the maximum num­ ber of digits to the right of the decimal point for numeric types, the number of digits to the right of the decimal point in the second's component of the data for timestamp types

SQL Reference for SAP Vora in SAP Data Hub 116 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Name Type Description

IS_NULLABLE varchar(5) Specifies whether the column is al­ lowed to accept null values: TRUE or FALSE

Note that the POSITION column shows the order of columns in the query result of a select statement.

1.6.4 SYS.VIEWS

SYS.VIEWS contains information about views.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

VIEW_NAME varchar(256) Name of the view

VIEW_OID bigint Object ID of the view

DEFINITION varchar(*) View definition string; content may change in future versions

1.6.5 SYS.CONSTRAINTS

SYS.CONSTRAINTS contains information about all constraints in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

COLUMN_NAME varchar(256) Name of the column

POSITION integer Ordinal position of the column in a re­ cord

CONSTRAINT_NAME varchar(256) Name of the constraint

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 117 Name Type Description

IS_PRIMARY_KEY varchar(5) TRUE if the constraint is a primary key constraint, otherwise FALSE

IS_UNIQUE_KEY varchar(5) TRUE if the constraint is a unique con­ straint, otherwise FALSE

1.6.6 SYS.MATERIALIZED_VIEWS

SYS.MATERIALIZED_VIEWS contains information about materialized views.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

VIEW_NAME varchar(256) Name of the view

VIEW_OID bigint Object ID of the view

DEFINITION varchar(*) View definition string; content may change in future versions

IS_HIERARCHY varchar(5) TRUE if the view is a hierarchy, other­ wise FALSE

1.6.7 SYS.MATERIALIZED_VIEW_COLUMNS

SYS.MATERIALIZED_VIEW_COLUMNS contains information about all columns of materialized views in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

VIEW_NAME varchar(256) Name of the view

VIEW_OID bigint Object ID of the view

COLUMN_NAME varchar(256) Name of the column

SQL Reference for SAP Vora in SAP Data Hub 118 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Name Type Description

POSITION integer Ordinal position of the column in a re­ cord

COLUMN_ID bigint Object ID of the column

DATA_TYPE_NAME varchar(256) String-representation of the SQL type of the column; content may change in future versions

LENGTH integer The max number of chars for CHAR types, number of max digits in decimal format for numeric types

SCALE integer The numeric types: the maximum num­ ber of digits to the right of the decimal point for numeric types, the number of digits to the right of the decimal point in the second's component of the data for timestamp types

IS_NULLABLE varchar(5) Specifies whether the column is al­ lowed to accept null values: TRUE or FALSE

1.6.8 SYS.SYNONYMS

SYS.SYNONYMS contains information about synonyms. Note that it is currently always empty.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

SYNONYM_NAME varchar(256) Name of the synonym

OBJECT_SCHEMA varchar(256) Schema name of the referenced object

OBJECT_NAME varchar(256) Name of the referenced object

OBJECT_TYPE varchar(32) Type of the referenced object

IS_VALID varchar(5) Specifies whether the synonym is valid or not

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 119 1.6.9 SYS.DUMMY

SYS.DUMMY contains dummy information. It has only one fixed row.

Structure

Name Type Description

DUMMY char(1) Dummy value

1.6.10 SYS.VORA_DATABASE

SYS.VORA_DATABASE contains information about the instance of the current Vora database.

Structure

Name Type Description

VERSION varchar(256) Database version

1.6.11 SYS.M_DATABASE

SYS.M_DATABASE contains HANA-compatible information about the instance of the current Vora database.

Structure

Name Type Description

SYSTEM_ID varchar(3) HANA-compatible system ID

DATABASE_NAME varchar(256) Name of the database

VERSION varchar(256) Database version, same as in SYS.VORA_DATABASE

SQL Reference for SAP Vora in SAP Data Hub 120 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.6.12 SYS.VORA_CAPABILITIES

SYS.VORA_CAPABILITIES contains information about the HANA capabilities supported by the current database.

Structure

Name Type Description

CAPABILITY_NAME varchar(256) Name of the capability

CAPABILITY_ID bigint HANA ID of the capability

ENABLED boolean True, if capability is enabled on the cur­ rent database

CAPABILITY_DESCRIPTION varchar(256) Functional description of the capability

1.6.13 SYS.VORA_FUNCTIONS

SYS.VORA_FUNCTIONS contains information about SQL functions available in the current database.

Structure

Name Type Description

FUNCTION_NAME varchar(256) Name of the function

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 121 1.6.14 SYS.VORA_TABLES

SYS.VORA_TABLES contains information about all tables in the current database, including Vora-specific information.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

TABLE_OID bigint Object ID of the table

TABLE_TYPE varchar(16) Table type: IN-MEMORY or DISK

TABLE_CATEGORY varchar(16) Table category: STREAMING, TRANS­ ACTIONAL, DATASOURCE, or MATERI­ ALIZED_VIEW

HAS_PRIMARY_KEY varchar(5) TRUE if the table has a primary key, otherwise FALSE

PARTITION_SCHEME_OID bigint Object ID of the partition scheme, NULL if the talbe is not partitioned

1.6.15 SYS.VORA_TABLE_COLUMNS

SYS.TABLE_COLUMNS contains information about all columns of all tables in the current database, including Vora-specific information.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

TABLE_OID bigint Object ID of the table

COLUMN_NAME varchar(256) Name of the column

POSITION integer Ordinal position of the column in a re­ cord

COLUMN_ID bigint Object ID of the column

SQL Reference for SAP Vora in SAP Data Hub 122 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Name Type Description

DATA_TYPE_NAME varchar(256) Name of the data type

LENGTH integer The max number of chars for CHAR types, number of max digits in decimal format for numeric types

SCALE integer The numeric types: the maximum num­ ber of digits to the right of the decimal point for numeric types, the number of digits to the right of the decimal point in the second's component of the data for timestamp types

IS_NULLABLE varchar(5) Specifies whether the column is al­ lowed to accept null values: TRUE or FALSE

IS_PRIMARY_KEY varchar(5) Specifies if the column is a primary key column: TRUE or FALSE

 Note

Note that the POSITION column shows the order of columns in the query result of a select statement.

1.6.16 SYS.VORA_DATASOURCES

SYS.VORA_DATASOURCES contains information about all the table datasources in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

DATASOURCE_NAME varchar(256) Name of the datasource

DATASOURCE_OID bigint Object ID of the datasource

DATASOURCE_CONNECTION_NAME varchar(256) Name of the datasource connection

DATASOURCE_LOADED_STATUS varchar(256) ('LOADED', 'DROPPED', 'UNSET')

DATASOURCE_ON_ERROR_MODE varchar(256) ('CONTINUE', 'ABORT', 'UNSET')

DATASOURCE_LOADING_TIME none Approximate time the datasource was last loaded

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 123 1.6.17 SYS.VORA_PARTITION_SCHEMES

SYS.VORA_PARTITION_SCHEMES contains information about all partition schemes in the current database, including Vora-specific information.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

PARTITION_SCHEME_NAME varchar(256) Name of the partition scheme

PARTITION_SCHEME_OID bigint Object ID of the partition scheme

PARTITION_FUNCTION_OID bigint Object ID of the partition function

COLOCATION varchar(5) TRUE if the partition scheme locates the same partitions of multiple tables on the same node, otherwise FALSE

1.6.18 SYS.VORA_PARTITION_FUNCTIONS

SYS.VORA_PARTITION_FUNCTIONS contains information about all partition functions in the current database, including Vora-specific information.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

PARTITION_FUNCTION_NAME varchar(256) Name of the partition function

PARTITION_FUNCTION_OID bigint Object ID of the partition function

SQL Reference for SAP Vora in SAP Data Hub 124 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.6.19 SYS.VORA_PARTITION_PARAMETERS

SYS.VORA_PARTITION_PARAMETERS contains information about all partition parameters in the current database, including Vora-specific information.

Structure

Name Type Description

PARTITION_PARAMETER_NAME varchar(256) Name of the partition parameter

PARTITION_PARAMETER_OID bigint Object ID of the partition parameter

PARTITION_FUNCTION_OID bigint Object ID of the partition function

POSITION integer Ordinal position of the parameter in the partition function

DATA_TYPE_NAME varchar(256) String representation of the SQL type of the column; content may change in fu­ ture versions

LENGTH integer The max number of chars for CHAR types, number of max digits in decimal format for numeric types

SCALE integer The numeric types: the maximum num­ ber of digits to the right of the decimal point for numeric types, the number of digits to the right of the decimal point in the second's component of the data for timestamp types

Note that the POSITION column reflects the order of parameters used in the CREATE PARTITION FUNCTION PF1(x, y, z) statement.

1.6.20 SYS.VORA_PARTITION_DEFINITIONS

SYS.VORA_PARTITION_DEFINITIONS contains information about all partition definitions in the current database, including Vora-specific information.

Structure

Name Type Description

PARTITION_DEFINITION_OID bigint Object ID of the partition definition

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 125 Name Type Description

PARTITION_FUNCTION_OID bigint Object ID of the partition function

PARTITION_TYPE varchar(16) Partitioning type. In this version: one of HASH, RANGE, INTERVAL

PARTITION_EXPRESSION varchar(*) Partition expression

PARTITION_COUNT bigint Partition count

PARTITION_INTERVAL varchar(256) Partition interval. Relevant for partition­ ing type INTERVAL, otherwise NULL.

PARTITION_BOUNDARIES varchar(*) Partition boundaries. Relevant for parti­ tioning type RANGE, otherwise NULL.

1.6.21 SYS.OBJECTS

SYS.OBJECTS contains information about all objects in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

OBJECT_NAME varchar(256) Name of the object

OBJECT_TYPE varchar(32) Type of the object

OBJECT_OID bigint Object ID of the object

1.6.22 SYS.OBJECT_VERSIONS

SYS.OBJECT_VERSIONS contains information about object versions in the current database.

Structure

Name Type Description

OBJECT_NAME varchar(256) Name of the object

OBJECT_OID bigint Object ID of the object

SQL Reference for SAP Vora in SAP Data Hub 126 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Name Type Description

OBJECT_VERSION bigint Monotonically increasing version of the object

1.6.23 SYS.OBJECT_DEPENDENCIES

SYS.OBJECT_DEPENDENCIES contains information about dependencies of views and materialized views in the current database.

 Note

Currently, the DEPENDENCY_TYPE is always 1, indicating a direct dependency between base and dependent object.

Structure

Name Type Description

BASE_SCHEMA_NAME varchar(256) Name of the base schema

BASE_OBJECT_NAME varchar(256) Name of the base object

BASE_OBJECT_TYPE varchar(32) Type of the base object

BASE_OBJECT_OID bigint Object ID of the base object

DEPENDENT_SCHEMA_NAME varchar(256) Name of the dependent schema

DEPENDENT_OBJECT_NAME varchar(256) Name of the dependent object

DEPENDENT_OBJECT_TYPE varchar(32) Type of the dependent object

DEPENDENT_OBJECT_OID bigint Object ID of the dependent object

DEPENDENCY_TYPE integer The type of dependency between base and dependent object

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 127 1.6.24 SYS.ROLES

SYS.ROLES contains information about all roles in the current database.

Structure

Name Type Description

ROLE_NAME varchar(256) Name of the role

ROLE_ID bigint ID of the role

CREATOR varchar(256) The name of the user who created the role

1.6.25 SYS.USERS

SYS.USERS contains information about all users in the current database.

Structure

Name Type Description

USER_NAME varchar(256) Name of the user

USER_ID bigint ID of the user

CREATOR varchar(256) The creator of the user

USER_DEACTIVATED varchar(5) Whether the user is deactivated: TRUE or FALSE

SQL Reference for SAP Vora in SAP Data Hub 128 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.6.26 SYS.GRANTED_ROLES

SYS.GRANTED_ROLES contains information about all granted roles in the current database.

Structure

Name Type Description

GRANTEE varchar(256) User or role the role is granted to

GRANTEE_TYPE varchar(4) USER or ROLE

ROLE_NAME varchar(256) Name of the granted role

GRANTOR varchar(256) User who granted the role

IS_GRANTABLE varchar(5) Specifies whether the role was granted WITH ADMIN OPTION: TRUE, FALSE

1.6.27 SYS.GRANTED_PRIVILEGES

SYS.GRANTED_PRIVILEGES contains information about all granted privileges in the current database.

Structure

Name Type Description

GRANTEE varchar(256) User or role the privilege is granted to

GRANTOR varchar(256) User who granted the privilege

SCHEMA_NAME varchar(256) Schema name the object belongs to

OBJECT_NAME varchar(256) Object name of granted object

OBJECT_TYPE varchar(20) Type of the granted object like: TABLE, SCHEMA, ...

PRIVILEGE varchar(256) Privilege granted

IS_GRANTABLE varchar(5) Privilege was granted WITH GRANT OP­ TION, WITH ADMIN OPTION: TRUE, FALSE

IS_VALID varchar(5) Privilege is valid or it became invalid be­ cause of implicit revoking: TRUE, FALSE

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 129 1.6.28 SYS.AUDIT_POLICIES

SYS.AUDIT_POLICIES contains information about all auditlog policies created in the current database.

Structure

Name Type Description

AUDIT_POLICY_NAME varchar(256) Audit policy name

AUDIT_POLICY_OID BIGINT Object ID of the audit policy

EVENT_STATUS varchar(32) Status of the events to be audited: SUCCESSFUL EVENTS, UNSUCCESS­ FUL EVENTS, ALL EVENTS. Always ALL EVENTS

IS_AUDIT_POLICY_ACTIVE varchar(5) Audit policy is active: TRUE, FALSE. Al­ ways TRUE

IS_VALID varchar(32) TRUE, FALSE. An audit policy can be in­ valid if the referenced object does not exist.

EVENT_ACTION varchar(32) Action to be audited: SELECT, INSERT, UPDATE, DELETE, EXECUTE, GRANT ROLE, REVOKE ROLE, GRANT PRIVI­ LEGE, REVOKE PRIVILEGE

USER_NAME varchar(256) User whose actions are to be audited. Always ALL USERS.

OBJECT_TYPE varchar(32) Type of object to be audited. UN­ KNOWN if object does not exist or user can't access it. NULL if this is a system action policy.

OBJECT_SCHEMA varchar(256) Schema of the object to be audited.

OBJECT_NAME varchar(256) Name of the object to be audited.

SQL Reference for SAP Vora in SAP Data Hub 130 PUBLIC SQL Reference for SAP Vora in SAP Data Hub 1.6.29 SYS.VORA_STATISTICS

SYS.VORA_STATISTICS contains statistics about all tables in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

COLUMN_NAME varchar(256) Name of the column

ROW_COUNT bigint Row count values of the column

DISTINCT_COUNT bigint Distinct value counts of the column

NULL_COUNT bigint Null value counts of the column

MIN_VALUE bigint Minimum integer value of the column

MAX_VALUE bigint Maximum integer value of the column

MIN_VALUE_STRING varchar(256) Minimum string value of the column

MAX_VALUE_STRING varchar(256) Maximum string value of the column

1.6.30 SYS.VORA_SERIES_TABLES

SYS.VORA_SERIES_TABLES contains information about all vora series tables in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

PERIOD_COLUMN_OID bigint Object ID of the period column

PERIOD_TYPE_NAME varchar (256) Name of the period type

IS_EQUIDISTANT varchar(5) TRUE if the period column has equidis­ tant timestamps, otherwise FALSE

INCREMENT_BY varchar(256) Distance between equidistant time­ stamps

MIN_VALUE varchar(256) Earliest timestamp recorded

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 131 Name Type Description

MAX_VALUE varchar(256) Latest timestamp recorded

1.6.31 SYS.SERIES_KEY_COLUMNS

SYS.SERIES_KEY_COLUMNS contains information about all series key columns in the current database.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

COLUMN_NAME varchar(256) Name of the column

POSITION integer Ordinal position of the column in a re­ cord

1.6.32 SYS.VORA_DATASOURCE_FILES

SYS.VORA_DATASOURCE_FILES contains information about the files connected to vora datasources.

Structure

Name Type Description

SCHEMA_NAME varchar(256) Name of the schema

TABLE_NAME varchar(256) Name of the table

DATASOURCE_NAME varchar(256) Name of the datasource

DATASOURCE_OID bigint Object ID of the datasource

DATASOURCE_CONNECTION_NAME varchar(256) Name of the datasource connection

DATASOURCE_LOADED_STATUS varchar(256) See SYS.VORA_DATASOURCES [page 123]

DATASOURCE_LOADING_TIME timestamp without timezone See SYS.VORA_DATASOURCES [page 123]

FILE_PATH varchar(256) Internal effective path to filesystem

SQL Reference for SAP Vora in SAP Data Hub 132 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Name Type Description

FILE_ETAG varchar(256) Internal tag identifying file content equality

FILE_BYTE_SIZE bigint Filesize in bytes

FILE_MODIFICATION_TIME timestamp without timezone File modification time as exposed by the filesystem

1.7 SAP VORA Configuration Framework

Related Information

Alter System [page 133]

1.7.1 Alter System

The Alter System configuration statement allows to change the settings in Vora.

Syntax

alter_system ::= ALTER SYSTEM ALTER CONFIGURATION '(' layer_description ')' (SET|UNSET) parameter_key_value_list [WITH RECONFIGURE]

layer_description ::= config_file_name ',' config_layer parameter_key_value_list ::= parameter_key_value_entry { ',' parameter_key_value_entry }

parameter_key_value_entry ::= '(' section_name ',' parameter_name ')' [= parameter_value]

Description

Note that the parameter strings are case insensitive. Each parameter is part of a section, can be applied to one or more configuration layers, and has a data type and a default value.

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 133 There are numerous of parameters that can be configured. The complete list can be seen by using the following statement:

SELECT * FROM SYS.INTERNAL_CONFIGURATION;

Example output filtered by section 'semantic':

 Sample Code

SELECT * FROM SYS.INTERNAL_CONFIGURATION WHERE SECTION = 'semantic';

SET­ SET­ DATA_TYPE_N LAYER_NAME SECTION TING_NAME TING_VALUE AME LENGTH SCALE

DEFAULT semantic allow_de­ false BOOLEAN ? ? lete_data­ source_tables

DEFAULT semantic max_num_col­ 1000 BIGINT 19 0 umn_per_table

DEFAULT semantic max_num_hash 16000 BIGINT 19 0 _partitions

DEFAULT semantic allow_in­ false BOOLEAN ? ? sert_data­ source_tables

DEFAULT semantic allow_up­ false BOOLEAN ? ? sert_data­ source_tables

DEFAULT semantic allow_up­ false BOOLEAN ? ? date_data­ source_tables

 Note

The 'DEFAULT' is 'SYSTEM'.

Current available sections:

Section

landscape

tracing

formats

afsi

disk

qo

internal

hana_capabilities

series

SQL Reference for SAP Vora in SAP Data Hub 134 PUBLIC SQL Reference for SAP Vora in SAP Data Hub Section

tc

semantic

audit_admin

persistance

Parameters

SET|UNSET Either sets the parameter_name to some parameter_value or unsets it (then no parameter_value is specified). WITH RECONFIGURE Currently, this clause is ignored (the system is always reconfigured once a setting is set). config_file_name Name of the file where the configuration is stored. Currently only 'vora' is allowed here. config_layer Specifies which part of the configuration is updated. Possible values here are 'SYSTEM' and 'SESSION'. section_name Designates which part of the system is updated. Examples: 'semantic', 'relational', 'tracing', etc. parameter_name Specifies which parameter to change. Examples: 'api_trace_level', 'sql_filescan_cache_size', 'enable_sql_on_files', etc. parameter_value The value to be set, which should be of the same type as parameter. Examples: 100, TRUE, 'debug', etc.

Examples

Set the Transaction Coordinator component tracing level to debug:

ALTER SYSTEM ALTER CONFIGURATION ('vora', 'system') SET ('TRACING', 'TC_TRACe_LEVEL') = 'debug';

SQL Reference for SAP Vora in SAP Data Hub SQL Reference for SAP Vora in SAP Data Hub PUBLIC 135 Important Disclaimers and Legal Information

Hyperlinks

Some links are classified by an icon and/or a mouseover text. These links provide additional information. About the icons:

● Links with the icon : You are entering a Web site that is not hosted by SAP. By using such links, you agree (unless expressly stated otherwise in your agreements with SAP) to this:

● The content of the linked-to site is not SAP documentation. You may not infer any product claims against SAP based on this information. ● SAP does not agree or disagree with the content on the linked-to site, nor does SAP warrant the availability and correctness. SAP shall not be liable for any damages caused by the use of such content unless damages have been caused by SAP's gross negligence or willful misconduct.

● Links with the icon : You are leaving the documentation for that particular SAP product or service and are entering a SAP-hosted Web site. By using such links, you agree that (unless expressly stated otherwise in your agreements with SAP) you may not infer any product claims against SAP based on this information.

Beta and Other Experimental Features

Experimental features are not part of the officially delivered scope that SAP guarantees for future releases. This means that experimental features may be changed by SAP at any time for any reason without notice. Experimental features are not for productive use. You may not demonstrate, test, examine, evaluate or otherwise use the experimental features in a live operating environment or with data that has not been sufficiently backed up. The purpose of experimental features is to get feedback early on, allowing customers and partners to influence the future product accordingly. By providing your feedback (e.g. in the SAP Community), you accept that intellectual property rights of the contributions or derivative works shall remain the exclusive property of SAP.

Example Code

Any software coding and/or code snippets are examples. They are not for productive use. The example code is only intended to better explain and visualize the syntax and phrasing rules. SAP does not warrant the correctness and completeness of the example code. SAP shall not be liable for errors or damages caused by the use of example code unless damages have been caused by SAP's gross negligence or willful misconduct.

Gender-Related Language

We try not to use gender-specific word forms and formulations. As appropriate for context and readability, SAP may use masculine word forms to refer to all genders.

SQL Reference for SAP Vora in SAP Data Hub 136 PUBLIC Important Disclaimers and Legal Information SQL Reference for SAP Vora in SAP Data Hub Important Disclaimers and Legal Information PUBLIC 137 www.sap.com/contactsap

© 2019 SAP SE or an SAP affiliate company. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP affiliate company. The information contained herein may be changed without prior notice.

Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.

Please see https://www.sap.com/about/legal/trademark.html for additional trademark information and notices.

THE BEST RUN