def importTextSchema( schemaJson ): try: if 'name' not in schemaJson: print('[ERROR] No table name defined in the schema json. Key \'name\' required of type STRING:\nExiting now\n.') exit( -1 ) if 'columns' not in schemaJson: print('[ERROR] No columns defined in the schema json. Key \'columns\' required of type [OBJECT]:\nExiting now\n.') exit( -1 ) print('[INFO] Creating temp landing table.') table_def = TableDefinition('temptable'); for c in schemaJson['columns']: colFunc = typeObj['TEXT'] colType = colFunc() table_def.add_column(c['name'], colType) if ( table_def == None ): print('[ERROR] A fatal error occurred while creating the temp table:\nExiting now\n.') exit( -1 ) except HyperException as e: print('[ERROR] A fatal error occurred while reading the schema definition:\n', e, '\nExiting now.') exit( -1 ) return table_def
def createTabTable(tableName, columnHeading, dataTypes): extract_table = TableDefinition(table_name=TableName("Extract", tableName)) for head in columnHeading: extract_table.add_column(head, eval(mapper[dataTypes.pop(0)])) return extract_table
def importSchema( schemaJson ): try: if 'name' not in schemaJson: print('[ERROR] No table name defined in the schema json. Key \'name\' required of type STRING:\nExiting now\n.') exit( -1 ) if 'columns' not in schemaJson: print('[ERROR] No columns defined in the schema json. Key \'columns\' required of type [OBJECT]:\nExiting now\n.') exit( -1 ) table_def = TableDefinition(schemaJson['name']); for c in schemaJson['columns']: if ( 'name' not in c ): print('No column name defined in the schema json. Key \'name\' required of type STRING:\nExiting now\n.') exit( -1 ) colFunc = typeObj['TEXT'] if( 'type' in c and c['type'] in typeObj): colFunc = typeObj[c['type']] if (c['type'] == 'CHAR'): if ( 'length' not in c ): print('No length defined for CHAR column', c['name'],'\nKey \'length\' required of type INTEGER:\nExiting now\n.') exit( -1 ) colType = colFunc(c['length']) elif (c['type'] == 'VARCHAR'): if ( 'length' not in c ): print('No length defined for VARCHAR column', c['name'],'\nKey \'length\' required of type INTEGER:\nExiting now\n.') exit( -1 ) colType = colFunc(c['length']) elif (c['type'] == 'NUMERIC'): if ( 'precision' not in c or 'scale' not in c ): print('No precision and/or scale defined for NUMERIC column', c['name'],'\nKeys \'precision\' and \'scale\' required of type INTEGER:\nExiting now\n.') exit( -1 ) colType = colFunc(c['precision'], c['scale']) else: colType = colFunc() else: colType = colFunc() if( 'collation' in c and c['collation'] in collationObj): colCollation = collationObj[c['collation']] table_def.add_column(c['name'], colType, colCollation) else: table_def.add_column(c['name'], colType) if ( table_def == None ): print('[ERROR] A fatal error occurred while creating the table:\nExiting now\n.') exit( -1 ) except HyperException as e: print('[ERROR] A fatal error occurred while reading the schema definition:\n', e, '\nExiting now.') exit( -1 ) return table_def
def createHyperTable(): columns = getConfig() page_table = TableDefinition(table_name="Page") for i in range(0, len(columns)): if columns[i]['DataType'] == "String": dt = SqlType.text() elif columns[i]['DataType'] == "Date": dt = SqlType.date() else: dt = SqlType.big_int() page_table.add_column(columns[i]['ColumnName'], dt) return page_table