use of org.apache.phoenix.schema.PName in project phoenix by apache.
the class UpgradeUtil method updateIndexesSequenceIfPresent.
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);
}
use of org.apache.phoenix.schema.PName in project phoenix by apache.
the class SchemaUtil method getTableKey.
public static byte[] getTableKey(PTable dataTable) {
PName tenantId = dataTable.getTenantId();
PName schemaName = dataTable.getSchemaName();
return getTableKey(tenantId == null ? ByteUtil.EMPTY_BYTE_ARRAY : tenantId.getBytes(), schemaName == null ? ByteUtil.EMPTY_BYTE_ARRAY : schemaName.getBytes(), dataTable.getTableName().getBytes());
}
use of org.apache.phoenix.schema.PName in project phoenix by apache.
the class ColumnExpressionTest method testSerialization.
@Test
public void testSerialization() throws Exception {
int maxLen = 30;
int scale = 5;
PName colName = PNameFactory.newName("c1");
PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PDecimal.INSTANCE, maxLen, scale, true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
dOut.flush();
ColumnExpression colExp2 = new KeyValueColumnExpression();
byte[] bytes = baos.toByteArray();
DataInputStream dIn = new DataInputStream(new ByteArrayInputStream(bytes, 0, bytes.length));
colExp2.readFields(dIn);
assertEquals(maxLen, colExp2.getMaxLength().intValue());
assertEquals(scale, colExp2.getScale().intValue());
assertEquals(PDecimal.INSTANCE, colExp2.getDataType());
}
use of org.apache.phoenix.schema.PName in project phoenix by apache.
the class ColumnExpressionTest method testSerializationWithNullScaleAndMaxLength.
@Test
public void testSerializationWithNullScaleAndMaxLength() throws Exception {
PName colName = PNameFactory.newName("c1");
PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PDecimal.INSTANCE, null, null, true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
dOut.flush();
ColumnExpression colExp2 = new KeyValueColumnExpression();
byte[] bytes = baos.toByteArray();
DataInputStream dIn = new DataInputStream(new ByteArrayInputStream(bytes, 0, bytes.length));
colExp2.readFields(dIn);
assertNull(colExp2.getMaxLength());
assertNull(colExp2.getScale());
}
use of org.apache.phoenix.schema.PName in project phoenix by apache.
the class ColumnExpressionTest method testSerializationWithNullMaxLength.
@Test
public void testSerializationWithNullMaxLength() throws Exception {
int scale = 5;
PName colName = PNameFactory.newName("c1");
PColumn column = new PColumnImpl(colName, PNameFactory.newName("f1"), PVarchar.INSTANCE, null, scale, true, 20, SortOrder.getDefault(), 0, null, false, null, false, false, colName.getBytes());
ColumnExpression colExp = new KeyValueColumnExpression(column);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dOut = new DataOutputStream(baos);
colExp.write(dOut);
dOut.flush();
ColumnExpression colExp2 = new KeyValueColumnExpression();
byte[] bytes = baos.toByteArray();
DataInputStream dIn = new DataInputStream(new ByteArrayInputStream(bytes, 0, bytes.length));
colExp2.readFields(dIn);
assertNull(colExp2.getMaxLength());
assertEquals(scale, colExp2.getScale().intValue());
assertEquals(PVarchar.INSTANCE, colExp2.getDataType());
}
Aggregations