Java Code Examples for org.apache.phoenix.util.SchemaUtil#normalizeIdentifier()
The following examples show how to use
org.apache.phoenix.util.SchemaUtil#normalizeIdentifier() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionParseNode.java From phoenix with Apache License 2.0 | 6 votes |
public BuiltInFunctionInfo(Class<? extends FunctionExpression> f, BuiltInFunction d) { this.name = SchemaUtil.normalizeIdentifier(d.name()); this.func = f; this.funcCtor = d.nodeClass() == FunctionParseNode.class ? getExpressionCtor(f, null) : null; this.nodeCtor = d.nodeClass() == FunctionParseNode.class ? null : getParseNodeCtor(d.nodeClass()); this.args = new BuiltInFunctionArgInfo[d.args().length]; int requiredArgCount = 0; for (int i = 0; i < args.length; i++) { this.args[i] = new BuiltInFunctionArgInfo(d.args()[i]); if (this.args[i].getDefaultValue() == null) { requiredArgCount = i + 1; } } this.requiredArgCount = requiredArgCount; this.isAggregate = AggregateFunction.class.isAssignableFrom(f); this.classType = d.classType(); this.derivedFunctions = d.derivedFunctions(); }
Example 2
Source File: ChangePermsStatement.java From phoenix with Apache License 2.0 | 6 votes |
public ChangePermsStatement(String permsString, boolean isSchemaName, TableName tableName, String schemaName, boolean isGroupName, LiteralParseNode ugNode, boolean isGrantStatement) { // PHOENIX-672 HBase API doesn't allow to revoke specific permissions, hence this parameter will be ignored here. // To comply with SQL standards, we may support the user given permissions to revoke specific permissions in future. // GRANT permissions statement requires this parameter and the parsing will fail if it is not specified in SQL if(permsString != null) { Permission permission = new Permission(permsString.getBytes()); permsList = permission.getActions(); } if(isSchemaName) { this.schemaName = SchemaUtil.normalizeIdentifier(schemaName); } else { this.tableName = tableName; } name = SchemaUtil.normalizeLiteral(ugNode); name = isGroupName ? AuthUtil.toGroupEntry(name) : name; this.isGrantStatement = isGrantStatement; }
Example 3
Source File: BaseEventSerializer.java From phoenix with Apache License 2.0 | 6 votes |
private int addToColumnMetadataInfo(final List<String> columns , final Map<String,Integer> qualifiedColumnsInfoMap, Map<String, Integer> unqualifiedColumnsInfoMap, int position) throws SQLException { Preconditions.checkNotNull(columns); Preconditions.checkNotNull(qualifiedColumnsInfoMap); Preconditions.checkNotNull(unqualifiedColumnsInfoMap); for (int i = 0 ; i < columns.size() ; i++) { String columnName = SchemaUtil.normalizeIdentifier(columns.get(i).trim()); Integer sqlType = unqualifiedColumnsInfoMap.get(columnName); if (sqlType == null) { sqlType = qualifiedColumnsInfoMap.get(columnName); if (sqlType == null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_NOT_FOUND) .setColumnName(columnName).setTableName(this.fullTableName).build().buildException(); } } columnMetadata[position] = new ColumnInfo(columnName, sqlType); position++; } return position; }
Example 4
Source File: IndexTool.java From phoenix with Apache License 2.0 | 5 votes |
/** * Checks for the validity of the index table passed to the job. * @param connection * @param masterTable * @param indexTable * @param tenantId * @return * @throws SQLException */ public static boolean isValidIndexTable(final Connection connection, final String masterTable, final String indexTable, final String tenantId) throws SQLException { final DatabaseMetaData dbMetaData = connection.getMetaData(); final String schemaName = SchemaUtil.getSchemaNameFromFullName(masterTable); final String tableName = SchemaUtil.normalizeIdentifier(SchemaUtil.getTableNameFromFullName(masterTable)); ResultSet rs = null; try { String catalog = ""; if (tenantId != null) { catalog = tenantId; } rs = dbMetaData.getIndexInfo(catalog, schemaName, tableName, false, false); while (rs.next()) { final String indexName = rs.getString(6); if (indexTable.equalsIgnoreCase(indexName)) { return true; } } } finally { if (rs != null) { rs.close(); } } return false; }
Example 5
Source File: SubselectRewriter.java From phoenix with Apache License 2.0 | 5 votes |
private SubselectRewriter(ColumnResolver resolver, List<AliasedNode> aliasedNodes, String tableAlias) { super(resolver, aliasedNodes.size()); this.tableAlias = tableAlias; this.aliasMap = new HashMap<String, ParseNode>(); for (AliasedNode aliasedNode : aliasedNodes) { String alias = aliasedNode.getAlias(); ParseNode node = aliasedNode.getNode(); if (alias == null) { alias = SchemaUtil.normalizeIdentifier(node.getAlias()); } if (alias != null) { aliasMap.put(SchemaUtil.getColumnName(tableAlias, alias), node); } } }
Example 6
Source File: FunctionParseNode.java From phoenix with Apache License 2.0 | 5 votes |
BuiltInFunctionInfo(Class<? extends FunctionExpression> f, BuiltInFunction d) { this.name = SchemaUtil.normalizeIdentifier(d.name()); this.funcCtor = d.nodeClass() == FunctionParseNode.class ? getExpressionCtor(f) : null; this.nodeCtor = d.nodeClass() == FunctionParseNode.class ? null : getParseNodeCtor(d.nodeClass()); this.args = new BuiltInFunctionArgInfo[d.args().length]; int requiredArgCount = 0; for (int i = 0; i < args.length; i++) { this.args[i] = new BuiltInFunctionArgInfo(d.args()[i]); if (this.args[i].getDefaultValue() == null) { requiredArgCount = i + 1; } } this.requiredArgCount = requiredArgCount; this.isAggregate = AggregateFunction.class.isAssignableFrom(f); }
Example 7
Source File: ConcreteTableNode.java From phoenix with Apache License 2.0 | 5 votes |
ConcreteTableNode(String alias, TableName name, Double tableSamplingRate) { super(SchemaUtil.normalizeIdentifier(alias)); this.name = name; if(tableSamplingRate==null){ this.tableSamplingRate=DEFAULT_TABLE_SAMPLING_RATE; }else if(tableSamplingRate<0d||tableSamplingRate>100d){ throw new IllegalArgumentException("TableSamplingRate is out of bound of 0 and 100"); }else{ this.tableSamplingRate=tableSamplingRate; } }
Example 8
Source File: ColumnFamilyDef.java From phoenix with Apache License 2.0 | 4 votes |
ColumnFamilyDef(String name, List<ColumnDef> columnDefs, Map<String,Object> props) { this.name = SchemaUtil.normalizeIdentifier(name); this.columnDefs = ImmutableList.copyOf(columnDefs); this.props = props == null ? Collections.<String,Object>emptyMap() : props; }
Example 9
Source File: AliasedNode.java From phoenix with Apache License 2.0 | 4 votes |
public AliasedNode(String alias, ParseNode node) { this.isCaseSensitve = alias != null && SchemaUtil.isCaseSensitive(alias); this.alias = alias == null ? null : SchemaUtil.normalizeIdentifier(alias); this.node = node; }
Example 10
Source File: PropertyName.java From phoenix with Apache License 2.0 | 4 votes |
PropertyName(String familyName, String propertyName) { this.familyName = familyName == null ? null : new NamedNode(familyName); this.propertyName = SchemaUtil.normalizeIdentifier(propertyName);; }
Example 11
Source File: DerivedTableNode.java From phoenix with Apache License 2.0 | 4 votes |
DerivedTableNode(String alias, SelectStatement select) { super(SchemaUtil.normalizeIdentifier(alias)); this.select = select; }
Example 12
Source File: TableName.java From phoenix with Apache License 2.0 | 4 votes |
private TableName(String schemaName, String tableName, boolean normalize) { this.schemaName = normalize ? SchemaUtil.normalizeIdentifier(schemaName) : schemaName; this.isSchemaNameCaseSensitive = normalize ? SchemaUtil.isCaseSensitive(schemaName) : false; this.tableName = normalize ? SchemaUtil.normalizeIdentifier(tableName) : tableName; this.isTableNameCaseSensitive = normalize ? SchemaUtil.isCaseSensitive(tableName) : false; }
Example 13
Source File: NamedNode.java From phoenix with Apache License 2.0 | 4 votes |
NamedNode(String name) { this.name = SchemaUtil.normalizeIdentifier(name); this.isCaseSensitive = name == null ? false : SchemaUtil.isCaseSensitive(name); }
Example 14
Source File: PropertyName.java From phoenix with Apache License 2.0 | 4 votes |
PropertyName(String familyName, String propertyName) { this.familyName = familyName == null ? null : new NamedNode(familyName); this.propertyName = SchemaUtil.normalizeIdentifier(propertyName);; }
Example 15
Source File: NamedNode.java From phoenix with Apache License 2.0 | 4 votes |
NamedNode(String name) { this.name = SchemaUtil.normalizeIdentifier(name); this.isCaseSensitive = name == null ? false : SchemaUtil.isCaseSensitive(name); }
Example 16
Source File: FunctionParseNode.java From phoenix with Apache License 2.0 | 4 votes |
FunctionParseNode(String name, List<ParseNode> children, BuiltInFunctionInfo info) { super(children); this.name = SchemaUtil.normalizeIdentifier(name); this.info = info; }
Example 17
Source File: ColumnFamilyDef.java From phoenix with Apache License 2.0 | 4 votes |
ColumnFamilyDef(String name, List<ColumnDef> columnDefs, Map<String,Object> props) { this.name = SchemaUtil.normalizeIdentifier(name); this.columnDefs = ImmutableList.copyOf(columnDefs); this.props = props == null ? Collections.<String,Object>emptyMap() : props; }
Example 18
Source File: TableName.java From phoenix with Apache License 2.0 | 4 votes |
private TableName(String schemaName, String tableName, boolean normalize) { this.schemaName = normalize ? SchemaUtil.normalizeIdentifier(schemaName) : schemaName; this.isSchemaNameCaseSensitive = normalize ? SchemaUtil.isCaseSensitive(schemaName) : false; this.tableName = normalize ? SchemaUtil.normalizeIdentifier(tableName) : tableName; this.isTableNameCaseSensitive = normalize ? SchemaUtil.isCaseSensitive(tableName) : false; }
Example 19
Source File: EmptyColumnIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testWithBasicTableAndNoAdditionalCols() throws Exception { // Define the test schema. TableOptions tableOptions = TableOptions.withDefaults(); tableOptions.getTablePKColumns().add("ID"); tableOptions.getTablePKColumnTypes().add("CHAR(15)"); tableOptions.getTableColumns().clear(); tableOptions.getTableColumnTypes().clear(); final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl()); schemaBuilder.withTableOptions(tableOptions).build(); // Define the test data. DataSupplier dataSupplier = new DataSupplier() { final String orgId = String.format("00D0x000%s", schemaBuilder.getDataOptions().getUniqueName()); final String kp = SchemaUtil.normalizeIdentifier(schemaBuilder.getEntityKeyPrefix()); @Override public List<Object> getValues(int rowIndex) { String id = String.format("00A0y000%07d", rowIndex); return Lists.newArrayList(new Object[] { orgId, kp, id }); } }; // Create a test data writer for the above schema. DataWriter dataWriter = new BasicDataWriter(); try (Connection connection = DriverManager.getConnection(getUrl())) { connection.setAutoCommit(true); dataWriter.setConnection(connection); dataWriter.setDataSupplier(dataSupplier); dataWriter.setUpsertColumns(Lists.newArrayList("OID", "KP", "ID")); dataWriter.setTargetEntity(schemaBuilder.getEntityTableName()); // Write the data and run validations ExpectedTestResults expectedTestResults = new ExpectedTestResults(DEFAULT_NUM_ROWS, 0, 0); upsertDataAndRunValidations(DEFAULT_NUM_ROWS, expectedTestResults, dataWriter, schemaBuilder, null); } }
Example 20
Source File: EmptyColumnIT.java From phoenix with Apache License 2.0 | 4 votes |
/** * This test uses a simple table and index and * runs with different combinations of * table properties, index types (local or global) and column family options. */ @Test public void testWhenTableWithIndexAndVariousOptions() throws Exception { // Run for different combinations of // table properties, index types (local or global) and column family options. for (String additionalProps : Lists .newArrayList("COLUMN_ENCODED_BYTES=0", "DEFAULT_COLUMN_FAMILY='Z'")) { StringBuilder withTableProps = new StringBuilder(); withTableProps.append("MULTI_TENANT=true,").append(additionalProps); for (boolean isTableIndexLocal : Lists.newArrayList(true, false)) { for (OtherOptions options : getTableColumnFamilyOptions()) { // Define the test table schema. TableOptions tableOptions = TableOptions.withDefaults(); tableOptions.getTablePKColumns().add("ID"); tableOptions.getTablePKColumnTypes().add("CHAR(15)"); tableOptions.setTableProps(withTableProps.toString()); // Define the index on the test table. TableIndexOptions tableIndexOptions = TableIndexOptions.withDefaults(); tableIndexOptions.setLocal(isTableIndexLocal); // Build the schema with the above options final SchemaBuilder schemaBuilder = new SchemaBuilder(getUrl()); schemaBuilder.withTableOptions(tableOptions) .withTableIndexOptions(tableIndexOptions).withOtherOptions(options) .build(); // Define the test data provider. DataSupplier dataSupplier = new DataSupplier() { final String orgId = String.format("00D0x000%s", schemaBuilder.getDataOptions().getUniqueName()); final String kp = SchemaUtil.normalizeIdentifier(schemaBuilder.getEntityKeyPrefix()); @Override public List<Object> getValues(int rowIndex) { Random rnd = new Random(); String id = String.format("00A0y000%07d", rowIndex); String col1 = String.format("a%05d", rowIndex + rnd.nextInt(MAX_ROWS)); String col2 = String.format("b%05d", rowIndex + rnd.nextInt(MAX_ROWS)); String col3 = String.format("c%05d", rowIndex + rnd.nextInt(MAX_ROWS)); return Lists .newArrayList(new Object[] { orgId, kp, id, col1, col2, col3 }); } }; // Create a test data writer for the above schema. DataWriter dataWriter = new BasicDataWriter(); try (Connection connection = DriverManager.getConnection(getUrl())) { connection.setAutoCommit(true); dataWriter.setConnection(connection); dataWriter.setDataSupplier(dataSupplier); dataWriter.setUpsertColumns( Lists.newArrayList("OID", "KP", "ID", "COL1", "COL2", "COL3")); dataWriter.setTargetEntity(schemaBuilder.getEntityTableName()); // dataSupplier.upsertValues column positions to be used for partial updates. List<Integer> columnsForPartialUpdates = Lists.newArrayList(0, 1, 2, 3, 5); // COL3 is the include column for the table index in this schema => index pos of 2 // and there are no global and view indexes. List<Integer> includeColumnPositionOfIndexes = Lists.newArrayList(2, null, null); /** * When table indexes are local i.e index rows are co-located. * AND * When there are more than one index and * the CFs of the include columns match. * Then the # of index rows in the table (when local) and * in the index table (when global) * is => # of rows * # of indexes * * But in this schema there is only one index => * # of index rows = # of upserted rows. */ // Write the data and run validations ExpectedTestResults expectedTestResults = new ExpectedTestResults(DEFAULT_NUM_ROWS, DEFAULT_NUM_ROWS, 0); upsertDataAndRunValidations(DEFAULT_NUM_ROWS, expectedTestResults, dataWriter, schemaBuilder, columnsForPartialUpdates, includeColumnPositionOfIndexes); } } } } }