return rewrite(statement, new IndexStatementRewriter(dataResolver, multiTableRewriteMap));
}
@Override
public ParseNode visit(ColumnParseNode node) throws SQLException {
ColumnRef dataColRef = getResolver().resolveColumn(node.getSchemaName(), node.getTableName(), node.getName());
TableName tName = null;
if (multiTableRewriteMap != null) {
TableRef origRef = dataColRef.getTableRef();
TableRef tableRef = multiTableRewriteMap.get(origRef);
if (tableRef == null)
return node;
if (origRef.getTableAlias() != null) {
tName = FACTORY.table(null, origRef.getTableAlias());
} else {
String schemaName = tableRef.getTable().getSchemaName().getString();
schemaName = schemaName.length() == 0 ? null : '"' + schemaName + '"';
String tableName = '"' + tableRef.getTable().getTableName().getString() + '"';
tName = FACTORY.table(schemaName, tableName);
}
}
String indexColName = IndexUtil.getIndexColumnName(dataColRef.getColumn());
// Same alias as before, but use the index column name instead of the data column name
ParseNode indexColNode = new ColumnParseNode(tName, indexColName, node.getAlias());
PDataType indexColType = IndexUtil.getIndexColumnDataType(dataColRef.getColumn());
PDataType dataColType = dataColRef.getColumn().getDataType();
// Coerce index column reference back to same type as data column so that
// expression behave exactly the same. No need to invert, as this will be done
// automatically as needed. If node is used at the top level, do not convert, as
// otherwise the wrapper gets in the way in the group by clause. For example,