public NamedTableNode namedTable(String alias, TableName name, Double tableSamplingRate) { return new NamedTableNode(alias, name, tableSamplingRate); }
@Override public TableNode visit(NamedTableNode namedTableNode) throws SQLException { TableRef tableRef = resolveTable(namedTableNode.getAlias(), namedTableNode.getName()); TableRef replaceRef = replacement.get(tableRef); if (replaceRef == null) return namedTableNode; String alias = namedTableNode.getAlias(); return FACTORY.namedTable(alias == null ? null : '"' + alias + '"', getReplacedTableName(replaceRef), namedTableNode.getDynamicColumns(), namedTableNode.getTableSamplingRate()); }
@Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { buf.append(this.getName().toString()); if (!dynColumns.isEmpty()) { buf.append('('); for (ColumnDef def : dynColumns) { buf.append(def); buf.append(','); } buf.setLength(buf.length()-1); buf.append(')'); } if (this.getAlias() != null) buf.append(" " + this.getAlias()); if (this.getTableSamplingRate() != null) buf.append(" TABLESAMPLE " + this.getTableSamplingRate()); buf.append(' '); }
protected TableRef createTableRef(String connectionSchemaName, NamedTableNode tableNode, boolean updateCacheImmediately, boolean alwaysHitServer) throws SQLException { String tableName = tableNode.getName().getTableName(); String schemaName = tableNode.getName().getSchemaName(); schemaName = connection.getSchema() != null && schemaName == null ? connection.getSchema() : schemaName; long timeStamp = QueryConstants.UNSET_TIMESTAMP; tableNode.getName().equals(mutatingTableName) ){ alwaysHitServer = true; List<ColumnDef> dynamicColumns = tableNode.getDynamicColumns(); theTable = addDynamicColumns(dynamicColumns, theTable); if (timeStamp != QueryConstants.UNSET_TIMESTAMP) { timeStamp += tsAddition; TableRef tableRef = new TableRef(tableNode.getAlias(), theTable, timeStamp, !dynamicColumns.isEmpty()); if (logger.isDebugEnabled() && timeStamp != QueryConstants.UNSET_TIMESTAMP) { logger.debug(LogUtil.addCustomAnnotations("Re-resolved stale table " + fullTableName + " with seqNum " + tableRef.getTable().getSequenceNumber() + " at timestamp " + tableRef.getTable().getTimeStamp() + " with " + tableRef.getTable().getColumns().size() + " columns: " + tableRef.getTable().getColumns(), connection));
public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode table, long timeStamp, Map<String, UDFParseNode> udfParseNodes, boolean isNamespaceMapped) throws SQLException { super(connection, 0, false, udfParseNodes, null); List<PColumnFamily> families = Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size()); for (ColumnDef def : table.getDynamicColumns()) { if (def.getColumnDefName().getFamilyName() != null) { families.add(new PColumnFamilyImpl(PNameFactory.newName(def.getColumnDefName().getFamilyName()),Collections.<PColumn>emptyList()));//, NON_ENCODED_QUALIFIERS)); String schema = table.getName().getSchemaName(); if (connection.getSchema() != null) { schema = schema != null ? schema : connection.getSchema(); String tableName = table.getName().getTableName(); PName name = PNameFactory.newName(SchemaUtil.getTableName(schema, tableName)); PTable theTable = new PTableImpl.Builder() .setNamespaceMapped(isNamespaceMapped) .build(); theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable); alias = null; tableRefs = ImmutableList.of(new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty())); schemas = ImmutableList.of(new PSchema(theTable.getSchemaName().toString(), timeStamp));
public IndexExpressionParseNodeRewriter(PTable index, String alias, PhoenixConnection connection, Map<String, UDFParseNode> udfParseNodes) throws SQLException { indexedParseNodeToColumnParseNodeMap = Maps.newHashMapWithExpectedSize(index.getColumns().size()); NamedTableNode tableNode = NamedTableNode.create(alias, TableName.create(index.getParentSchemaName().getString(), index.getParentTableName().getString()), Collections.<ColumnDef> emptyList()); ColumnResolver dataResolver = FromCompiler.getResolver(tableNode, connection, udfParseNodes); StatementContext context = new StatementContext(new PhoenixStatement(connection), dataResolver); IndexStatementRewriter rewriter = new IndexStatementRewriter(dataResolver, null, true); ExpressionCompiler expressionCompiler = new ExpressionCompiler(context); int indexPosOffset = (index.getBucketNum() == null ? 0 : 1) + (index.isMultiTenant() ? 1 : 0) + (index.getViewIndexId() == null ? 0 : 1); List<PColumn> pkColumns = index.getPKColumns(); for (int i=indexPosOffset; i<pkColumns.size(); ++i) { PColumn column = pkColumns.get(i); String expressionStr = IndexUtil.getIndexColumnExpressionStr(column); ParseNode expressionParseNode = SQLParser.parseCondition(expressionStr); String colName = "\"" + column.getName().getString() + "\""; Expression dataExpression = expressionParseNode.accept(expressionCompiler); PDataType expressionDataType = dataExpression.getDataType(); ParseNode indexedParseNode = expressionParseNode.accept(rewriter); PDataType indexColType = IndexUtil.getIndexColumnDataType(dataExpression.isNullable(), expressionDataType); ParseNode columnParseNode = new ColumnParseNode(alias!=null ? TableName.create(null, alias) : null, colName, null); if ( indexColType != expressionDataType) { columnParseNode = NODE_FACTORY.cast(columnParseNode, expressionDataType, null, null); } indexedParseNodeToColumnParseNodeMap.put(indexedParseNode, columnParseNode); } }
try { String dataTableName = statement.getTableName(); String indexName = statement.getTable().getName().getTableName(); boolean isAsync = statement.isAsync(); String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString(); PTable table = FromCompiler.getResolver(statement, connection).getTables().get(0).getTable(); String schemaName = statement.getTable().getName().getSchemaName(); String tableName = table.getTableName().getString(); MutationPlan plan = new PostDDLCompiler(connection).compile(Collections.singletonList(indexRef), null, null, Collections.<PColumn>emptyList(), ts); connection.getQueryServices().updateData(plan); NamedTableNode dataTableNode = NamedTableNode.create(null, TableName.create(schemaName, dataTableName), Collections.<ColumnDef>emptyList());
public CreateIndexStatement(NamedNode indexTableName, NamedTableNode dataTable, IndexKeyConstraint indexKeyConstraint, List<ColumnName> includeColumns, List<ParseNode> splits, ListMultimap<String,Pair<String,Object>> props, boolean ifNotExists, IndexType indexType, boolean async, int bindCount, Map<String, UDFParseNode> udfParseNodes) { super(dataTable, bindCount); this.indexTableName =TableName.create(dataTable.getName().getSchemaName(),indexTableName.getName()); this.indexKeyConstraint = indexKeyConstraint == null ? IndexKeyConstraint.EMPTY : indexKeyConstraint; this.includeColumns = includeColumns == null ? Collections.<ColumnName>emptyList() : includeColumns; this.splitNodes = splits == null ? Collections.<ParseNode>emptyList() : splits; this.props = props == null ? ArrayListMultimap.<String,Pair<String,Object>>create() : props; this.ifNotExists = ifNotExists; this.indexType = indexType; this.async = async; this.udfParseNodes = udfParseNodes; }
@Override public Void visit(NamedTableNode tableNode) throws SQLException { String alias = tableNode.getAlias(); TableRef tableRef = createTableRef(connectionSchemaName, tableNode, true, false); PTable theTable = tableRef.getTable(); if (alias != null) { tableMap.put(alias, tableRef); } String name = theTable.getName().getString(); //avoid having one name mapped to two identical TableRef. if (alias == null || !alias.equals(name)) { tableMap.put(name, tableRef); } tables.add(tableRef); return null; }
@Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { buf.append(this.getName().toString()); if (!dynColumns.isEmpty()) { buf.append('('); for (ColumnDef def : dynColumns) { buf.append(def); buf.append(','); } buf.setLength(buf.length()-1); buf.append(')'); } if (this.getAlias() != null) buf.append(" " + this.getAlias()); if (this.getTableSamplingRate() != null) buf.append(" TABLESAMPLE " + this.getTableSamplingRate()); buf.append(' '); }
protected TableRef createTableRef(String connectionSchemaName, NamedTableNode tableNode, boolean updateCacheImmediately, boolean alwaysHitServer) throws SQLException { String tableName = tableNode.getName().getTableName(); String schemaName = tableNode.getName().getSchemaName(); schemaName = connection.getSchema() != null && schemaName == null ? connection.getSchema() : schemaName; long timeStamp = QueryConstants.UNSET_TIMESTAMP; tableNode.getName().equals(mutatingTableName) ){ alwaysHitServer = true; List<ColumnDef> dynamicColumns = tableNode.getDynamicColumns(); theTable = addDynamicColumns(dynamicColumns, theTable); if (timeStamp != QueryConstants.UNSET_TIMESTAMP) { timeStamp += tsAddition; TableRef tableRef = new TableRef(tableNode.getAlias(), theTable, timeStamp, !dynamicColumns.isEmpty()); if (logger.isDebugEnabled() && timeStamp != QueryConstants.UNSET_TIMESTAMP) { logger.debug(LogUtil.addCustomAnnotations("Re-resolved stale table " + fullTableName + " with seqNum " + tableRef.getTable().getSequenceNumber() + " at timestamp " + tableRef.getTable().getTimeStamp() + " with " + tableRef.getTable().getColumns().size() + " columns: " + tableRef.getTable().getColumns(), connection));
public SingleTableColumnResolver(PhoenixConnection connection, NamedTableNode tableNode, boolean updateCacheImmediately, int tsAddition, Map<String, UDFParseNode> udfParseNodes, boolean alwaysHitServer, TableName mutatingTableName) throws SQLException { super(connection, tsAddition, updateCacheImmediately, udfParseNodes, mutatingTableName); alias = tableNode.getAlias(); TableRef tableRef = createTableRef(tableNode.getName().getSchemaName(), tableNode, updateCacheImmediately, alwaysHitServer); PSchema schema = new PSchema(tableRef.getTable().getSchemaName().toString()); tableRefs = ImmutableList.of(tableRef); schemas = ImmutableList.of(schema); }
List<PColumn> targetColumns; NamedTableNode tableNode = upsert.getTable(); String tableName = tableNode.getName().getTableName(); String schemaName = tableNode.getName().getSchemaName(); QueryPlan queryPlanToBe = null; int nValuesToSet; if (columnNodes.isEmpty() || columnNodes.size() == upsert.getTable().getDynamicColumns().size()) { nColumnsToSet = allColumnsToBe.size() - posOffset; columnIndexesToBe = new int[nColumnsToSet]; assert(select != null); select = SubselectRewriter.flatten(select, connection); ColumnResolver selectResolver = FromCompiler.getResolverForQuery(select, connection, false, upsert.getTable().getName()); select = StatementNormalizer.normalize(select, selectResolver); select = prependTenantAndViewConstants(table, select, tenantIdStr, addViewColumnsToBe, useServerTimestampToBe); SelectStatement transformedSelect = SubqueryRewriter.transform(select, selectResolver, connection); if (transformedSelect != select) { selectResolver = FromCompiler.getResolverForQuery(transformedSelect, connection, false, upsert.getTable().getName()); select = StatementNormalizer.normalize(transformedSelect, selectResolver);
NamedTableNode indexNode = NamedTableNode.create(null, indexTableName, null); ColumnResolver resolver = FromCompiler.getResolver(indexNode, conn.unwrap(PhoenixConnection.class)); PTable indexTable = resolver.getTables().get(0).getTable();
try { String dataTableName = statement.getTableName(); String indexName = statement.getTable().getName().getTableName(); boolean isAsync = statement.isAsync(); String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString(); PTable table = FromCompiler.getResolver(statement, connection).getTables().get(0).getTable(); String schemaName = statement.getTable().getName().getSchemaName(); String tableName = table.getTableName().getString(); MutationPlan plan = new PostDDLCompiler(connection).compile(Collections.singletonList(indexRef), null, null, Collections.<PColumn>emptyList(), ts); connection.getQueryServices().updateData(plan); NamedTableNode dataTableNode = NamedTableNode.create(null, TableName.create(schemaName, dataTableName), Collections.<ColumnDef>emptyList());
public QueryLogger createQueryLogger(CompilableStatement stmt, String sql) throws SQLException { boolean isSystemTable=false; if(stmt instanceof ExecutableSelectStatement){ TableNode from = ((ExecutableSelectStatement)stmt).getFrom(); if(from instanceof NamedTableNode){ String schemaName = ((NamedTableNode)from).getName().getSchemaName(); if(schemaName==null){ schemaName=connection.getSchema(); } if(PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA.equals(schemaName)){ isSystemTable=true; } } } QueryLogger queryLogger = QueryLogger.getInstance(connection,isSystemTable); QueryLoggerUtil.logInitialDetails(queryLogger, connection.getTenantId(), connection.getQueryServices(), sql, getParameters()); return queryLogger; }
@Override public Void visit(NamedTableNode tableNode) throws SQLException { String alias = tableNode.getAlias(); TableRef tableRef = createTableRef(connectionSchemaName, tableNode, true, false); PTable theTable = tableRef.getTable(); if (alias != null) { tableMap.put(alias, tableRef); } String name = theTable.getName().getString(); //avoid having one name mapped to two identical TableRef. if (alias == null || !alias.equals(name)) { tableMap.put(name, tableRef); } tables.add(tableRef); return null; }
@Override public Pair<Table, List<JoinSpec>> visit(NamedTableNode namedTableNode) throws SQLException { TableRef tableRef = resolveTable(namedTableNode.getAlias(), namedTableNode.getName()); boolean isWildCard = isWildCardSelectForTable(select.getSelect(), tableRef, origResolver); Table table = new Table(namedTableNode, isWildCard, namedTableNode.getDynamicColumns(), namedTableNode.getTableSamplingRate(), tableRef); return new Pair<Table, List<JoinSpec>>(table, null); }
@Override public void toSQL(ColumnResolver resolver, StringBuilder buf) { buf.append(this.getName().toString()); if (!dynColumns.isEmpty()) { buf.append('('); for (ColumnDef def : dynColumns) { buf.append(def); buf.append(','); } buf.setLength(buf.length()-1); buf.append(')'); } if (this.getAlias() != null) buf.append(" " + this.getAlias()); if (this.getTableSamplingRate() != null) buf.append(" TABLESAMPLE " + this.getTableSamplingRate()); buf.append(' '); }