public String getSchemaName() { return tableName == null ? null : tableName.getSchemaName(); }
protected CreateTableStatement(TableName tableName, ListMultimap<String,Pair<String,Object>> props, List<ColumnDef> columns, PrimaryKeyConstraint pkConstraint, List<ParseNode> splitNodes, PTableType tableType, boolean ifNotExists, TableName baseTableName, ParseNode whereClause, int bindCount, Boolean immutableRows) { this.tableName = tableName; this.props = props == null ? ImmutableListMultimap.<String,Pair<String,Object>>of() : props; this.tableType = PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA.equals(tableName.getSchemaName()) ? PTableType.SYSTEM : tableType; this.columns = columns == null ? ImmutableList.<ColumnDef>of() : ImmutableList.<ColumnDef>copyOf(columns); this.pkConstraint = pkConstraint == null ? PrimaryKeyConstraint.EMPTY : pkConstraint; this.splitNodes = splitNodes == null ? Collections.<ParseNode>emptyList() : ImmutableList.copyOf(splitNodes); this.bindCount = bindCount; this.ifNotExists = ifNotExists; this.baseTableName = baseTableName; this.whereClause = whereClause; this.immutableRows = immutableRows; }
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; }
private TableRef resolveTable(String alias, TableName name) throws SQLException { if (alias != null) return resolver.resolveTable(null, alias); return resolver.resolveTable(name.getSchemaName(), name.getTableName()); }
private TableRef resolveTable(String alias, TableName name) throws SQLException { if (alias != null) return origResolver.resolveTable(null, alias); return origResolver.resolveTable(name.getSchemaName(), name.getTableName()); }
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); }
private void validateNodeIsStateless(CreateSequenceStatement sequence, ParseNode node, SQLExceptionCode code) throws SQLException { if (!node.isStateless()) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } }
public MutationState dropTable(DropTableStatement statement) throws SQLException { String schemaName = connection.getSchema() != null && statement.getTableName().getSchemaName() == null ? connection.getSchema() : statement.getTableName().getSchemaName(); String tableName = statement.getTableName().getTableName(); return dropTable(schemaName, tableName, null, statement.getTableType(), statement.ifExists(), statement.cascade(), statement.getSkipAddingParentColumns()); }
public MutationState dropIndex(DropIndexStatement statement) throws SQLException { String schemaName = statement.getTableName().getSchemaName(); String tableName = statement.getIndexName().getName(); String parentTableName = statement.getTableName().getTableName(); return dropTable(schemaName, tableName, parentTableName, PTableType.INDEX, statement.ifExists(), false, false); }
@Override public ParseNode visit(TableWildcardParseNode node) throws SQLException { TableName tName = getReplacedTableName(getResolver().resolveTable(node.getTableName().getSchemaName(), node.getTableName().getTableName())); return tName == null ? node : TableWildcardParseNode.create(tName, true); }
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; }
private boolean isWildCardSelectForTable(List<AliasedNode> select, TableRef tableRef, ColumnResolver resolver) throws SQLException { ColumnRefParseNodeVisitor visitor = new ColumnRefParseNodeVisitor(resolver, statement.getConnection()); for (AliasedNode aliasedNode : select) { ParseNode node = aliasedNode.getNode(); if (node instanceof TableWildcardParseNode) { TableName tableName = ((TableWildcardParseNode) node).getTableName(); if (tableRef.equals(resolver.resolveTable(tableName.getSchemaName(), tableName.getTableName()))) { return true; } } } return false; }
@Override public Expression visit(SequenceValueParseNode node) throws SQLException { // NEXT VALUE FOR is only supported in SELECT expressions and UPSERT VALUES throw new SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_USE_OF_NEXT_VALUE_FOR) .setSchemaName(node.getTableName().getSchemaName()) .setTableName(node.getTableName().getTableName()).build().buildException(); }
public MutationState dropSequence(DropSequenceStatement statement) throws SQLException { Long scn = connection.getSCN(); long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn; String schemaName = connection.getSchema() != null && statement.getSequenceName().getSchemaName() == null ? connection.getSchema() : statement.getSequenceName().getSchemaName(); String sequenceName = statement.getSequenceName().getTableName(); String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString(); try { connection.getQueryServices().dropSequence(tenantId, schemaName, sequenceName, timestamp); } catch (SequenceNotFoundException e) { if (statement.ifExists()) { return new MutationState(0, 0, connection); } throw e; } return new MutationState(1, 1000, connection); }
String tenantId = tenantName == null ? null : tenantName.getString(); TableName tableName = node.getTableName(); if (tableName.getSchemaName() == null && statement.getConnection().getSchema() != null) { tableName = TableName.create(statement.getConnection().getSchema(), tableName.getTableName()); SequenceKey key = new SequenceKey(tenantId, tableName.getSchemaName(), tableName.getTableName(), nSaltBuckets); SequenceValueExpression expression = sequenceMap.get(key); if (expression == null) {
private long evalExpression(CreateSequenceStatement sequence, StatementContext context, Expression expression, SQLExceptionCode code) throws SQLException { ImmutableBytesWritable ptr = context.getTempPtr(); expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { TableName sequenceName = sequence.getSequenceName(); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), code); } return (Long) PLong.INSTANCE.toObject(ptr, expression.getDataType()); }
expression.evaluate(null, ptr); if (ptr.getLength() == 0 || !expression.getDataType().isCoercibleTo(PLong.INSTANCE)) { throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), SQLExceptionCode.NUM_SEQ_TO_ALLOCATE_MUST_BE_CONSTANT); throw SequenceUtil.getException(sequenceName.getSchemaName(), sequenceName.getTableName(), SQLExceptionCode.NUM_SEQ_TO_ALLOCATE_MUST_BE_CONSTANT);
@Override public Expression visit(SequenceValueParseNode node) throws SQLException { if (aggregateFunction != null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_USE_OF_NEXT_VALUE_FOR) .setSchemaName(node.getTableName().getSchemaName()) .setTableName(node.getTableName().getTableName()).build().buildException(); } return context.getSequenceManager().newSequenceReference(node); }
String schema = table.getName().getSchemaName(); if (connection.getSchema() != null) { schema = schema != null ? schema : connection.getSchema();
public MutationState createSequence(CreateSequenceStatement statement, long startWith, long incrementBy, long cacheSize, long minValue, long maxValue) throws SQLException { Long scn = connection.getSCN(); long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn; String tenantId = connection.getTenantId() == null ? null : connection.getTenantId().getString(); String schemaName=statement.getSequenceName().getSchemaName(); if (SchemaUtil.isNamespaceMappingEnabled(null, connection.getQueryServices().getProps())) { if (schemaName == null || schemaName.equals(StringUtil.EMPTY_STRING)) { schemaName = connection.getSchema(); } if (schemaName != null) { FromCompiler.getResolverForSchema(schemaName, connection); } } return createSequence(tenantId, schemaName, statement .getSequenceName().getTableName(), statement.ifNotExists(), startWith, incrementBy, cacheSize, statement.getCycle(), minValue, maxValue, timestamp); }