Search in sources :

Example 36 with PName

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);
}
Also used : PName(org.apache.phoenix.schema.PName)

Example 37 with PName

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());
}
Also used : PName(org.apache.phoenix.schema.PName)

Example 38 with PName

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());
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) PColumnImpl(org.apache.phoenix.schema.PColumnImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) PName(org.apache.phoenix.schema.PName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 39 with PName

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());
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) PColumnImpl(org.apache.phoenix.schema.PColumnImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) PName(org.apache.phoenix.schema.PName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 40 with PName

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());
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) PColumnImpl(org.apache.phoenix.schema.PColumnImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) PName(org.apache.phoenix.schema.PName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

PName (org.apache.phoenix.schema.PName)45 PTable (org.apache.phoenix.schema.PTable)26 PColumn (org.apache.phoenix.schema.PColumn)18 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)13 Test (org.junit.Test)10 SQLException (java.sql.SQLException)9 Cell (org.apache.hadoop.hbase.Cell)9 PColumnImpl (org.apache.phoenix.schema.PColumnImpl)9 PTableKey (org.apache.phoenix.schema.PTableKey)9 TableRef (org.apache.phoenix.schema.TableRef)8 PSmallint (org.apache.phoenix.schema.types.PSmallint)8 Connection (java.sql.Connection)7 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)7 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)7 PTinyint (org.apache.phoenix.schema.types.PTinyint)7 List (java.util.List)6 Mutation (org.apache.hadoop.hbase.client.Mutation)6 Scan (org.apache.hadoop.hbase.client.Scan)6 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)6 IOException (java.io.IOException)5