public FunctionArgument(String argumentType, boolean isArrayType, boolean isConstant, LiteralExpression defaultValue, LiteralExpression minValue, LiteralExpression maxValue) { this.argumentType = PNameFactory.newName(argumentType); this.isArrayType = isArrayType; this.isConstant = isConstant; this.defaultValue = defaultValue; this.minValue = minValue; this.maxValue = maxValue; } public FunctionArgument(String argumentType, boolean isArrayType, boolean isConstant, LiteralExpression defaultValue,
public PFunction(PName tenantId, String functionName, List<FunctionArgument> args, String returnType, String className, String jarPath, long timeStamp, boolean temporary, boolean replace) { this.tenantId = tenantId; this.functionName = PNameFactory.newName(functionName); if (args == null){ this.args = new ArrayList<FunctionArgument>(); } else { this.args = args; } this.className = PNameFactory.newName(className); this.jarPath = jarPath == null ? null : PNameFactory.newName(jarPath); this.returnType = PNameFactory.newName(returnType); this.functionKey = new PTableKey(this.tenantId, this.functionName.getString()); this.timeStamp = timeStamp; int estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE + PNameFactory.getEstimatedSize(tenantId) + PNameFactory.getEstimatedSize(this.functionName) + PNameFactory.getEstimatedSize(this.className) + (jarPath==null?0:PNameFactory.getEstimatedSize(this.jarPath)); this.temporary = temporary; this.replace = replace; }
private PTableType(String serializedValue, String value) { this.serializedValue = serializedValue; this.value = PNameFactory.newName(value); }
public PSchema(String schemaName, long timeStamp) { this.schemaName = PNameFactory.newName(SchemaUtil.normalizeIdentifier(schemaName)); this.schemaKey = new PTableKey(null, this.schemaName.getString()); this.timeStamp = timeStamp; this.estimatedSize = SizedUtil.INT_SIZE + SizedUtil.LONG_SIZE + PNameFactory.getEstimatedSize(this.schemaName); }
@Override public PName apply(ByteString physicalName) { return PNameFactory.newName(physicalName.toByteArray()); } });
Preconditions.checkNotNull(this.rowKeyOrderOptimizable); PName fullName = PNameFactory.newName(SchemaUtil.getTableName( this.schemaName.getString(), this.tableName.getString())); int estimatedSize = SizedUtil.OBJECT_SIZE * 2 + 23 * SizedUtil.POINTER_SIZE + 4 * SizedUtil.INT_SIZE + 2 * SizedUtil.LONG_SIZE + 2 * SizedUtil.INT_OBJECT_SIZE + PNameFactory.getEstimatedSize(this.tenantId) + PNameFactory.getEstimatedSize(this.schemaName) + PNameFactory.getEstimatedSize(this.tableName) + PNameFactory.getEstimatedSize(this.pkName) + PNameFactory.getEstimatedSize(this.parentTableName) + PNameFactory.getEstimatedSize(this.defaultFamilyName); int numPKColumns = 0; List<PColumn> pkColumns; estimatedSize += PNameFactory.getEstimatedSize(this.parentName); for (PName physicalName : this.physicalNames) { estimatedSize += physicalName.getEstimatedSize(); .setKey(new PTableKey(this.tenantId, fullName.getString())) .setParentName(this.parentTableName == null ? null : PNameFactory.newName(SchemaUtil.getTableName( this.parentSchemaName != null ? this.parentSchemaName.getString() : null,
public static PName getPhysicalHBaseTableName(String schemaName, String tableName, boolean isNamespaceMapped) { if (!isNamespaceMapped) { return PNameFactory.newName(getTableNameAsBytes(schemaName, tableName)); } if (schemaName == null || schemaName.isEmpty()) { return PNameFactory.newName(tableName); } return PNameFactory.newName(schemaName + QueryConstants.NAMESPACE_SEPARATOR + tableName); }
public PSchema(String schemaName, long timeStamp) { this.schemaName = PNameFactory.newName(SchemaUtil.normalizeIdentifier(schemaName)); this.schemaKey = new PTableKey(null, this.schemaName.getString()); this.timeStamp = timeStamp; this.estimatedSize = SizedUtil.INT_SIZE + SizedUtil.LONG_SIZE + PNameFactory.getEstimatedSize(this.schemaName); }
private static PName newPName(byte[] keyBuffer, int keyOffset, int keyLength) { if (keyLength <= 0) { return null; } int length = getVarCharLength(keyBuffer, keyOffset, keyLength); return PNameFactory.newName(keyBuffer, keyOffset, length); }
public PSchema(String schemaName, long timeStamp) { this.schemaName = PNameFactory.newName(SchemaUtil.normalizeIdentifier(schemaName)); this.schemaKey = new PTableKey(null, this.schemaName.getString()); this.timeStamp = timeStamp; this.estimatedSize = SizedUtil.INT_SIZE + SizedUtil.LONG_SIZE + PNameFactory.getEstimatedSize(this.schemaName); }
public static @Nullable PName getTenantId(String url, Properties info) throws SQLException { String tenantId = findProperty(url, info, PhoenixRuntime.TENANT_ID_ATTRIB); return (tenantId == null ? null : PNameFactory.newName(tenantId)); }
public static PName newNormalizedName(String name) { return newName(SchemaUtil.normalizeIdentifier(name)); }
@Override public PName getPhysicalName() { if (physicalNames.isEmpty()) { return SchemaUtil.getPhysicalHBaseTableName(schemaName, tableName, isNamespaceMapped); } else { return PNameFactory.newName(physicalNames.get(0).getBytes()); } }
@Override public PName getParentSchemaName() { // a view on a table will not have a parent name but will have a physical table name (which is the parent) return (type!=PTableType.VIEW || parentName!=null) ? parentSchemaName : PNameFactory.newName(SchemaUtil.getSchemaNameFromFullName(getPhysicalName().getBytes())); }
@Override public PName getParentTableName() { // a view on a table will not have a parent name but will have a physical table name (which is the parent) return (type!=PTableType.VIEW || parentName!=null) ? parentTableName : PNameFactory.newName(SchemaUtil.getTableNameFromFullName(getPhysicalName().getBytes())); }
public static SequenceKey getViewIndexSequenceKey(String tenantId, PName physicalName, int nSaltBuckets, boolean isNamespaceMapped) { // Create global sequence of the form: <prefixed base table name><tenant id> // rather than tenant-specific sequence, as it makes it much easier // to cleanup when the physical table is dropped, as we can delete // all global sequences leading with <prefix> + physical name. String schemaName = getViewIndexSequenceSchemaName(physicalName, isNamespaceMapped); String tableName = getViewIndexSequenceName(physicalName, PNameFactory.newName(tenantId), isNamespaceMapped); return new SequenceKey(isNamespaceMapped ? tenantId : null, schemaName, tableName, nSaltBuckets); }
public SharedTableState( org.apache.phoenix.coprocessor.generated.MetaDataProtos.SharedTableState sharedTable) { this.tenantId = sharedTable.hasTenantId() ? PNameFactory.newName(sharedTable.getTenantId().toByteArray()) : null; this.schemaName = PNameFactory.newName(sharedTable.getSchemaName().toByteArray()); this.tableName = PNameFactory.newName(sharedTable.getTableName().toByteArray()); this.columns = Lists.transform(sharedTable.getColumnsList(), new Function<org.apache.phoenix.coprocessor.generated.PTableProtos.PColumn, PColumn>() { @Override public PColumn apply(org.apache.phoenix.coprocessor.generated.PTableProtos.PColumn column) { return PColumnImpl.createFromProto(column); } }); this.physicalNames = Lists.transform(sharedTable.getPhysicalNamesList(), new Function<ByteString, PName>() { @Override public PName apply(ByteString physicalName) { return PNameFactory.newName(physicalName.toByteArray()); } }); this.viewIndexId = sharedTable.getViewIndexId(); this.viewIndexIdType = sharedTable.hasViewIndexIdType() ? PDataType.fromTypeId(sharedTable.getViewIndexIdType()) : MetaDataUtil.getLegacyViewIndexIdDataType(); }
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); this.tenantId = PNameFactory.newName(WritableUtils.readString(input)); this.functionClassName = WritableUtils.readString(input); String str = WritableUtils.readString(input); this.jarPath = str.length() == 0 ? null: str; constructUDFFunction(); }
private static void updateIndexesSequenceIfPresent(PhoenixConnection connection, PTable dataTable) throws SQLException { PName tenantId = connection.getTenantId(); PName physicalName = dataTable.getPhysicalName(); PName oldPhysicalName = PNameFactory.newName( physicalName.toString().replace(QueryConstants.NAMESPACE_SEPARATOR, QueryConstants.NAME_SEPARATOR)); String oldSchemaName = MetaDataUtil.getViewIndexSequenceSchemaName(oldPhysicalName, false); String newSchemaName = MetaDataUtil.getViewIndexSequenceSchemaName(physicalName, true); String newSequenceName = MetaDataUtil.getViewIndexSequenceName(physicalName, tenantId, true); // create new entry with new schema format String upsert = "UPSERT INTO " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " SELECT REGEXP_SPLIT(" + PhoenixDatabaseMetaData.SEQUENCE_NAME + ",'_')[3] ,\'" + newSchemaName + "\',\'" + newSequenceName + "\'," + START_WITH + "," + CURRENT_VALUE + "," + INCREMENT_BY + "," + CACHE_SIZE + "," + MIN_VALUE + "," + MAX_VALUE + "," + CYCLE_FLAG + "," + LIMIT_REACHED_FLAG + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " WHERE " + PhoenixDatabaseMetaData.TENANT_ID + " IS NULL AND " + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + " = '" + oldSchemaName + "'"; connection.createStatement().executeUpdate(upsert); // delete old sequence MetaDataUtil.deleteViewIndexSequences(connection, oldPhysicalName, false); }
protected PTable addDynamicColumns(List<ColumnDef> dynColumns, PTable theTable) throws SQLException { if (!dynColumns.isEmpty()) { List<PColumn> allcolumns = new ArrayList<PColumn>(); List<PColumn> existingColumns = theTable.getColumns(); // Need to skip the salting column, as it's handled in the PTable builder call below allcolumns.addAll(theTable.getBucketNum() == null ? existingColumns : existingColumns.subList(1, existingColumns.size())); // Position still based on with the salting columns int position = existingColumns.size(); PName defaultFamilyName = PNameFactory.newName(SchemaUtil.getEmptyColumnFamily(theTable)); for (ColumnDef dynColumn : dynColumns) { PName familyName = defaultFamilyName; PName name = PNameFactory.newName(dynColumn.getColumnDefName().getColumnName()); String family = dynColumn.getColumnDefName().getFamilyName(); if (family != null) { theTable.getColumnFamily(family); // Verifies that column family exists familyName = PNameFactory.newName(family); } allcolumns.add(new PColumnImpl(name, familyName, dynColumn.getDataType(), dynColumn.getMaxLength(), dynColumn.getScale(), dynColumn.isNull(), position, dynColumn.getSortOrder(), dynColumn.getArraySize(), null, false, dynColumn.getExpression(), false, true, Bytes.toBytes(dynColumn.getColumnDefName().getColumnName()), HConstants.LATEST_TIMESTAMP)); position++; } theTable = PTableImpl.builderWithColumns(theTable, allcolumns) .build(); } return theTable; }