use of org.apache.phoenix.schema.PTable in project phoenix by apache.
the class ConnectionlessQueryServicesImpl method getTable.
@Override
public MetaDataMutationResult getTable(PName tenantId, byte[] schemaBytes, byte[] tableBytes, long tableTimestamp, long clientTimestamp) throws SQLException {
// to get anything from the server (since we don't have a connection)
try {
String fullTableName = SchemaUtil.getTableName(schemaBytes, tableBytes);
PTable table = metaData.getTableRef(new PTableKey(tenantId, fullTableName)).getTable();
return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0, table, true);
} catch (TableNotFoundException e) {
return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, 0, null);
}
}
use of org.apache.phoenix.schema.PTable in project phoenix by apache.
the class BaseConnectionlessQueryTest method doSetup.
@BeforeClass
public static void doSetup() throws Exception {
startServer(getUrl());
ensureTableCreated(getUrl(), ATABLE_NAME);
ensureTableCreated(getUrl(), ENTITY_HISTORY_TABLE_NAME);
ensureTableCreated(getUrl(), FUNKY_NAME);
ensureTableCreated(getUrl(), PTSDB_NAME);
ensureTableCreated(getUrl(), PTSDB2_NAME);
ensureTableCreated(getUrl(), PTSDB3_NAME);
ensureTableCreated(getUrl(), MULTI_CF_NAME);
ensureTableCreated(getUrl(), TABLE_WITH_ARRAY);
Properties props = new Properties();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(HConstants.LATEST_TIMESTAMP));
PhoenixConnection conn = DriverManager.getConnection(PHOENIX_CONNECTIONLESS_JDBC_URL, props).unwrap(PhoenixConnection.class);
try {
PTable table = conn.getTable(new PTableKey(null, ATABLE_NAME));
ATABLE = table;
ORGANIZATION_ID = new ColumnRef(new TableRef(table), table.getColumnForColumnName("ORGANIZATION_ID").getPosition()).newColumnExpression();
ENTITY_ID = new ColumnRef(new TableRef(table), table.getColumnForColumnName("ENTITY_ID").getPosition()).newColumnExpression();
A_INTEGER = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
A_STRING = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
B_STRING = new ColumnRef(new TableRef(table), table.getColumnForColumnName("B_STRING").getPosition()).newColumnExpression();
A_DATE = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_DATE").getPosition()).newColumnExpression();
A_TIME = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_TIME").getPosition()).newColumnExpression();
A_TIMESTAMP = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_TIMESTAMP").getPosition()).newColumnExpression();
X_DECIMAL = new ColumnRef(new TableRef(table), table.getColumnForColumnName("X_DECIMAL").getPosition()).newColumnExpression();
} finally {
conn.close();
}
}
use of org.apache.phoenix.schema.PTable in project phoenix by apache.
the class LocalIndexIT method testLocalIndexRoundTrip.
@Ignore
public //FIXME: PHOENIX-3496
void testLocalIndexRoundTrip() throws Exception {
String tableName = schemaName + "." + generateUniqueName();
String indexName = "IDX_" + generateUniqueName();
String indexTableName = schemaName + "." + indexName;
createBaseTable(tableName, null, null);
Connection conn1 = DriverManager.getConnection(getUrl());
conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
conn1.createStatement().executeQuery("SELECT * FROM " + tableName).next();
PTable localIndex = conn1.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, indexTableName));
assertEquals(IndexType.LOCAL, localIndex.getIndexType());
assertNotNull(localIndex.getViewIndexId());
String tableName2 = "test_table" + generateUniqueName();
String indexName2 = "idx_test_table" + generateUniqueName();
String createTable = "CREATE TABLE IF NOT EXISTS " + tableName2 + " (user_time UNSIGNED_TIMESTAMP NOT NULL,user_id varchar NOT NULL,col1 varchar,col2 double," + "CONSTRAINT pk PRIMARY KEY(user_time,user_id)) SALT_BUCKETS = 20";
conn1.createStatement().execute(createTable);
conn1.createStatement().execute("CREATE local INDEX IF NOT EXISTS " + indexName2 + " on " + tableName2 + "(\"HOUR\"(user_time))");
conn1.createStatement().execute("upsert into " + tableName2 + " values(TO_TIME('2005-10-01 14:03:22.559'), 'foo')");
conn1.commit();
ResultSet rs = conn1.createStatement().executeQuery("select substr(to_char(user_time), 0, 10) as ddate, \"HOUR\"(user_time) as hhour, user_id, col1,col2 from " + tableName2 + " where \"HOUR\"(user_time)=14 group by user_id, col1, col2, ddate, hhour limit 1");
assertTrue(rs.next());
}
use of org.apache.phoenix.schema.PTable in project phoenix by apache.
the class IndexMaintainer method serialize.
/**
* For client-side to serialize all IndexMaintainers for a given table
* @param dataTable data table
* @param ptr bytes pointer to hold returned serialized value
* @param indexes indexes to serialize
*/
public static void serialize(PTable dataTable, ImmutableBytesWritable ptr, List<PTable> indexes, PhoenixConnection connection) {
Iterator<PTable> indexesItr = nonDisabledIndexIterator(indexes.iterator());
if ((dataTable.isImmutableRows()) || !indexesItr.hasNext()) {
indexesItr = enabledLocalIndexIterator(indexesItr);
if (!indexesItr.hasNext()) {
ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
return;
}
}
int nIndexes = 0;
while (indexesItr.hasNext()) {
nIndexes++;
indexesItr.next();
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(stream);
try {
// Encode data table salting in sign of number of indexes
WritableUtils.writeVInt(output, nIndexes * (dataTable.getBucketNum() == null ? 1 : -1));
// Write out data row key schema once, since it's the same for all index maintainers
dataTable.getRowKeySchema().write(output);
indexesItr = dataTable.isImmutableRows() ? enabledLocalIndexIterator(indexes.iterator()) : nonDisabledIndexIterator(indexes.iterator());
while (indexesItr.hasNext()) {
org.apache.phoenix.coprocessor.generated.ServerCachingProtos.IndexMaintainer proto = IndexMaintainer.toProto(indexesItr.next().getIndexMaintainer(dataTable, connection));
byte[] protoBytes = proto.toByteArray();
WritableUtils.writeVInt(output, protoBytes.length);
output.write(protoBytes);
}
} catch (IOException e) {
// Impossible
throw new RuntimeException(e);
}
ptr.set(stream.toByteArray(), 0, stream.size());
}
use of org.apache.phoenix.schema.PTable in project phoenix by apache.
the class PhoenixUtil method isDisabledWal.
public static boolean isDisabledWal(MetaDataClient metaDataClient, String tableName) throws SQLException {
String[] schemaInfo = getTableSchema(tableName.toUpperCase());
MetaDataMutationResult result = metaDataClient.updateCache(schemaInfo[0], schemaInfo[1]);
PTable dataTable = result.getTable();
return dataTable.isWALDisabled();
}
Aggregations