private static List getTableColumns(ISession session, Table table) throws IOException { List colNames = new ArrayList(); String tableName = table.getSchemaName() + "." + table.getName(); SeColumnDefinition[] cols = session.describe(tableName); for (int i = 0; i < cols.length; i++) { String colName = cols[i].getName(); colName = tableName + "." + colName; colNames.add(colName); } return colNames; } }
String tableName = qt.getSchemaName() + "." + qt.getName(); SeColumnDefinition[] cols; try {
@Override public void visit(Table table) { if (!withTCEs.contains(table.getFullyQualifiedName().toLowerCase())) { RelationID relationId = idfac.createRelationID(table.getSchemaName(), table.getName()); relations.add(relationId); } }
@Override public void visit(Table table) { if (!withTCEs.contains(table.getFullyQualifiedName().toLowerCase())) { RelationID relationId = idfac.createRelationID(table.getSchemaName(), table.getName()); relations.add(relationId); } }
@Override public void visit(Table table) { log.debug("visit(table)" + table); String tabName = table.getWholeTableName(); log.debug("looking for " + tabName + " in conversion map..."); Table ntab = map.get(tabName); log.debug("found: " + ntab); if (ntab != null) { log.debug("convert: " + table.getSchemaName() + "." + table.getName() + " -> " + ntab.getSchemaName() + "." + ntab.getName()); table.setName(ntab.getName()); table.setSchemaName(ntab.getSchemaName()); // leave alias intact } } }
private static List getTableColumns(ISession session, Table table) throws IOException { List colNames = new ArrayList(); String tableName = table.getSchemaName() + "." + table.getName(); SeColumnDefinition[] cols = session.describe(tableName); for (int i = 0; i < cols.length; i++) { String colName = cols[i].getName(); colName = tableName + "." + colName; colNames.add(colName); } return colNames; } }
@Override public void visit(Column column) { log.debug("visit(column)" + column); Table table = column.getTable(); log.debug("table: " + table); if (table != null && table.getName() != null) { String tabName = table.getWholeTableName(); log.debug("looking for " + tabName + " in conversion map..."); Table ntab = map.get(tabName); log.debug("found: " + ntab); if (ntab != null) { log.debug("convert: " + table.getSchemaName() + "." + table.getName() + " -> " + ntab.getSchemaName() + "." + ntab.getName()); table.setName(ntab.getName()); table.setSchemaName(ntab.getSchemaName()); // leave alias intact } } } }
public ImmutableMap<QualifiedAttributeID, Term> expandStar(ImmutableMap<QualifiedAttributeID, Term> attributes, Table table) { RelationID id = idfac.createRelationID(table.getSchemaName(), table.getName()); return attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() != null && e.getKey().getRelation().equals(id)) .collect(ImmutableCollectors.toMap( e -> new QualifiedAttributeID(null, e.getKey().getAttribute()), Map.Entry::getValue)); }
public ImmutableMap<QualifiedAttributeID, Term> expandStar(ImmutableMap<QualifiedAttributeID, Term> attributes, Table table) { RelationID id = idfac.createRelationID(table.getSchemaName(), table.getName()); return attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() != null && e.getKey().getRelation().equals(id)) .collect(ImmutableCollectors.toMap( e -> new QualifiedAttributeID(null, e.getKey().getAttribute()), Map.Entry::getValue)); }
@Override public void visit(AllTableColumns allTableColumns) { Table table = allTableColumns.getTable(); RelationID id = idfac.createRelationID(table.getSchemaName(), table.getName()); map = attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() != null && e.getKey().getRelation().equals(id)) .collect(ImmutableCollectors.toMap( e -> new QualifiedAttributeID(null, e.getKey().getAttribute()), Map.Entry::getValue)); }
@Override public void visit(AllTableColumns allTableColumns) { Table table = allTableColumns.getTable(); RelationID id = idfac.createRelationID(table.getSchemaName(), table.getName()); map = attributes.entrySet().stream() .filter(e -> e.getKey().getRelation() != null && e.getKey().getRelation().equals(id)) .collect(ImmutableCollectors.toMap( e -> new QualifiedAttributeID(null, e.getKey().getAttribute()), Map.Entry::getValue)); }
@Override public void visit(Table table) { if (!withTCEs.contains(table.getFullyQualifiedName().toLowerCase())) { RelationID relationId = idfac.createRelationID(table.getSchemaName(), table.getName()); relations.add(relationId); if (inSubSelect && subSelectAlias != null) { // ONLY SIMPLE SUBSELECTS, WITH ONE TABLE: see WhereClauseVisitor and ProjectionVisitor RelationID subSelectAliasId = idfac.createRelationID(null, subSelectAlias.getName()); tables.put(subSelectAliasId, relationId); } else { Alias as = table.getAlias(); RelationID aliasId = (as != null) ? idfac.createRelationID(null, as.getName()) : relationId; tables.put(aliasId, relationId); } } }
private Statement buildTruncateStatement(String defaultTableSpace, Truncate truncate) throws StatementExecutionException { if (truncate.getTable() == null) { throw new StatementExecutionException("missing table name"); } String tableSpace = truncate.getTable().getSchemaName(); if (tableSpace == null) { tableSpace = defaultTableSpace; } String tableName = truncate.getTable().getName(); return new TruncateTableStatement(tableSpace, tableName); }
static TableRef buildFrom(Table fromTable, String defaultTableSpace) { String tableSpace = fromTable.getSchemaName(); String tableName = fromTable.getName(); String tableAlias = tableName; if (fromTable.getAlias() != null && fromTable.getAlias().getName() != null) { tableAlias = fromTable.getAlias().getName(); } if (tableSpace == null) { tableSpace = defaultTableSpace; } return new TableRef(tableSpace, tableName, tableAlias); }
@Override public void visit(SelectExpressionItem selectExpressionItem) { Expression expr = selectExpressionItem.getExpression(); QuotedID name = getSelectItemAliasedId(selectExpressionItem); final Term var; if (expr instanceof Column) { Column column = (Column) expr; QuotedID columnId = idfac.createAttributeID(column.getColumnName()); Table table = column.getTable(); RelationID tableId = (table == null || table.getName() == null) ? null : idfac.createRelationID(table.getSchemaName(), table.getName()); QualifiedAttributeID attr = new QualifiedAttributeID(tableId, columnId); var = attributes.get(attr); if (var == null) throw new InvalidSelectQueryRuntimeException("Column not found", selectExpressionItem); } else { // whether the complex expression has an alias already been checked var = createVariable(name); } map = ImmutableMap.of(new QualifiedAttributeID(null, name), var); } }
@Override public void visit(SelectExpressionItem selectExpressionItem) { Expression expr = selectExpressionItem.getExpression(); QuotedID name = getSelectItemAliasedId(selectExpressionItem); final Term var; if (expr instanceof Column) { Column column = (Column) expr; QuotedID columnId = idfac.createAttributeID(column.getColumnName()); Table table = column.getTable(); RelationID tableId = (table == null || table.getName() == null) ? null : idfac.createRelationID(table.getSchemaName(), table.getName()); QualifiedAttributeID attr = new QualifiedAttributeID(tableId, columnId); var = attributes.get(attr); if (var == null) throw new InvalidSelectQueryRuntimeException("Column not found", selectExpressionItem); } else { // whether the complex expression has an alias already been checked var = createVariable(name); } map = ImmutableMap.of(new QualifiedAttributeID(null, name), var); } }
private Term getVariable(Column expression) { QuotedID column = idfac.createAttributeID(expression.getColumnName()); RelationID relation = null; if (expression.getTable().getName() != null) relation = idfac.createRelationID(expression.getTable().getSchemaName(), expression.getTable().getName()); QualifiedAttributeID qa = new QualifiedAttributeID(relation, column); return lookupTable.get(qa); }
public static void normalizeColumnName(QuotedIDFactory idfac, Column tableColumn) { QuotedID columnName = idfac.createAttributeID(tableColumn.getColumnName()); tableColumn.setColumnName(columnName.getSQLRendering()); Table table = tableColumn.getTable(); RelationID tableName = idfac.createRelationID(table.getSchemaName(), table.getName()); table.setSchemaName(tableName.getSchemaSQLRendering()); table.setName(tableName.getTableNameSQLRendering()); }
@Override public void visit(Table tableName) { RelationID id = idfac.createRelationID(tableName.getSchemaName(), tableName.getName()); // construct the predicate using the table name DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); relationIndex++; RelationID alias = (tableName.getAlias() != null) ? idfac.createRelationID(null, tableName.getAlias().getName()) : relation.getID(); ImmutableMap<QuotedID, Term> attributes = relation.getAttributes().stream() .collect(ImmutableCollectors.toMap(Attribute::getID, attribute -> createVariable(attribute.getID()))); // DEFAULT SCHEMA // TODO: to be improved if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) result = RAExpressionAttributes.create(attributes, alias, relation.getID().getSchemalessID()); else result = RAExpressionAttributes.create(attributes, alias); }
@Override public void visit(Table tableName) { RelationID id = idfac.createRelationID(tableName.getSchemaName(), tableName.getName()); // construct the predicate using the table name DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); relationIndex++; RelationID alias = (tableName.getAlias() != null) ? idfac.createRelationID(null, tableName.getAlias().getName()) : relation.getID(); ImmutableMap<QuotedID, Term> attributes = relation.getAttributes().stream() .collect(ImmutableCollectors.toMap(Attribute::getID, attribute -> createVariable(attribute.getID()))); // DEFAULT SCHEMA // TODO: to be improved if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) result = RAExpressionAttributes.create(attributes, alias, relation.getID().getSchemalessID()); else result = RAExpressionAttributes.create(attributes, alias); }