Class: TableUtils

tableUtils~ TableUtils

TableUtils provides convenience functions for test table handling

new TableUtils(connection)

Creates an TableUtils object.
Parameters:
Name Type Description
connection $.db.Connection database connection
Example
var TableUtils = $.import("sap.hana.testtools.unit.util", "tableUtils").TableUtils;
var connection = $.db.getConnection();
var tableUtils = new TableUtils(connection);

Methods

clearTableInUserSchema(testTableName)

Clears the test table that exists in the user schema.
Parameters:
Name Type Description
testTableName String the name of the table in the user schema to be cleared
Examples
tableUtils.clearTableInUserSchema("ORDERS");
var testTable = tableUtils.copyIntoUserSchema("SAP_HANA_TEST_DEMO", "ORDERS");
tableUtils.clearTableInUserSchema(testTable);

copyIntoUserSchema(tableSchema, tableName, newTableName) → {String}

Creates a test table as a copy of an existing table into the user schema. If the test table already exists, it will be deleted in advance.
Parameters:
Name Type Argument Default Description
tableSchema String the schema of the table to be copied (authoring/physical)
tableName String the name of the table to be copied
newTableName String <optional>
originName the name of the target table
Returns:
name of the copied test table including schema name
Type
String
Example
var testTable = tableUtils.copyIntoUserSchema("SAP_HANA_TEST_DEMO", "sap.hana.testtools.demo.objects::ORDERS", "ORDERS");

createTemporaryTable(tableAlias, tableSchema, tableName, data) → {String}

Creates a temporary table out of an existing table (structure) type. Fills the passed data into the test table.
Parameters:
Name Type Argument Description
tableAlias String the name of the temporary table
tableSchema String the schema of the existing table type
tableName String the name of the existing table (structure) type
data Object | Array | module:tableDataSet~TableDataSet <optional>
one ore multiple data lines
Returns:
name of temporary table
Type
String
Example
var singleEntry = {
    Id : "1",
    col2 : "A",
    COL3 : 10.1
};
var multEntries = {
    Id : [ "1", "2" ],
    col2 : [ "A", "B" ],
    COL3 : [ 10.1, 20.2 ]
};

var tmpTableNoData = tableUtils.createTemporaryTable("TMPTable1", "SCHEMA", "package.subpackage::TABLE");
var tmpTableWithSingleEntry = tableUtils.createTemporaryTable("TMPTable2", "SCHEMA", "package.subpackage::TABLE", singleEntry);
var tmpTableWithMultEntries = tableUtils.createTemporaryTable("TMPTable3", "SCHEMA", "package.subpackage::TABLE", multEntries);

createTestTableFromView(viewName, testTableName, keys, viewSchema) → {String}

Creates a test table like an existing view (non-OLAP) into the user schema. If the test table already exists, it will be deleted in advance.
Parameters:
Name Type Argument Default Description
viewName String the name of the view to be copied
testTableName String the name of the target table
keys Array <optional>
the column names that define the primary key of the target table
viewSchema String <optional>
"_SYS_BIC" the schema of the view to be copied
Returns:
name of the created test table including schema name
Type
String
Example
var testTable = tableUtils.createTestTableFromView("sap.hana.testtools.demo.objects.attribute_view_1/AT_PRODUCTS", "AT_PRODUCTS", [ "PRODUCT_ID" ]);

fillFromCsvFile(fullTableName, csvPackage, csvFile, csvProperties)

Fills a test table from a csv-file.
Parameters:
Name Type Argument Description
fullTableName String the table name including the schema name e.g. "SCHEMA"."package.subpackage::tableName"
csvPackage String the package of the .csv file
csvFile String the name of the .csv file that contains the data
csvProperties Object <optional>
defines the properties of the csv file to be imported
  • separator: An override for the separator character. Defaults to a semicolon (;)
  • headers: Indicates whether the data contains a header line. Defaults to (true)
  • decSeparator: An override for the decimal separator character. Defaults to a dot(.)
Example
var csvProperties = {
    separator : ";",
    headers : false,
    decSeparator : ".",
};
var copiedTableName = tableUtils.copyIntoUserSchema("SAP_HANA_TEST_DEMO", "sap.hana.testtools.demo.objects::ORDERS");
tableUtils.fillFromCsvFile(copiedTableName, "sap.hana.testtools.unit.util.test.data", "Orders.csv", csvProperties);

getPhysicalSchemaName(schemaName) → {String}

Tries to resolve schema mappings. Returns the authoring schema if no suitable schema mapping is found.
Parameters:
Name Type Description
schemaName String name of the authoring schema
Since:
  • 1.10.3
Returns:
the physical schema that the authoring schema maps to
Type
String

insertData(fullTableName, data)

Fills the passed data into the test table.
Parameters:
Name Type Description
fullTableName String the table name including the schema name e.g. "SCHEMA"."package.subpackage::TABLE"
data Object | Array | module:tableDataSet~TableDataSet one ore multiple data lines
Since:
  • 1.9.1
Example
var singleEntry = {
    Id : "1",
    col2 : "A",
    COL3 : 10.1
};
var multEntries = {
    Id : [ "1", "2" ],
    col2 : [ "A", "B" ],
    COL3 : [ 10.1, 20.2 ]
};

var copiedTableName = tableUtils.copyIntoUserSchema("SCHEMA", "package.subpackage::TABLE");
tableUtils.insertData(copiedTableName, singleEntry);
tableUtils.insertData(copiedTableName, multEntries);