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 testTableNameString 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 tableSchemaString the schema of the table to be copied (authoring/physical) tableNameString the name of the table to be copied newTableNameString <optional>
tableName 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 tableAliasString the name of the temporary table tableSchemaString the schema of the existing table type tableNameString the name of the existing table (structure) type dataObject | 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); -
createTestTableFromFunction(schema, functionName, testTableName, keys) → {String}
-
Creates a test table like the return type of an existing table function into the user schema. If the test table already exists, it will be deleted in advance.
Parameters:
Name Type Argument Default Description schemaString the schema of the table function functionNameString the name of the table function testTableNameString <optional>
functionName the name of the target table keysArray <optional>
the column names that define the primary key of the target table - Since:
- 1.11.0
Throws:
Error If the function provided is not a table function or the return type cannot be determined.Returns:
name of the created test table including schema name- Type
- String
Example
var testTable = tableUtils.createTestTableFromFunction("sap.hana.testtools.demo.objects.hdbprocedure_with_tablefunction/FilterProducts", "FilteredProducts"); -
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 viewNameString the name of the view to be copied testTableNameString the name of the target table keysArray <optional>
the column names that define the primary key of the target table viewSchemaString <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 fullTableNameString the table name including the schema name e.g. "SCHEMA"."package.subpackage::tableName" csvPackageString the package of the .csv file csvFileString the name of the .csv file that contains the data csvPropertiesObject <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 schemaNameString 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 fullTableNameString the table name including the schema name e.g. "SCHEMA"."package.subpackage::TABLE" dataObject | 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);