use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class ExploreMetadataTestRun method testGetColumns.
@Test
public void testGetColumns() throws Exception {
ArrayList<ColumnDesc> expectedColumnDescs = Lists.newArrayList(new ColumnDesc("TABLE_CAT", "STRING", 1, "Catalog name. NULL if not applicable"), new ColumnDesc("TABLE_SCHEM", "STRING", 2, "Schema name"), new ColumnDesc("TABLE_NAME", "STRING", 3, "Table name"), new ColumnDesc("COLUMN_NAME", "STRING", 4, "Column name"), new ColumnDesc("DATA_TYPE", "INT", 5, "SQL type from java.sql.Types"), new ColumnDesc("TYPE_NAME", "STRING", 6, "Data source dependent type name, " + "for a UDT the type name is fully qualified"), new ColumnDesc("COLUMN_SIZE", "INT", 7, "Column size. For char or date types" + " this is the maximum number of characters, for numeric or decimal" + " types this is precision."), new ColumnDesc("BUFFER_LENGTH", "TINYINT", 8, "Unused"), new ColumnDesc("DECIMAL_DIGITS", "INT", 9, "The number of fractional digits"), new ColumnDesc("NUM_PREC_RADIX", "INT", 10, "Radix (typically either 10 or 2)"), new ColumnDesc("NULLABLE", "INT", 11, "Is NULL allowed"), new ColumnDesc("REMARKS", "STRING", 12, "Comment describing column (may be null)"), new ColumnDesc("COLUMN_DEF", "STRING", 13, "Default value (may be null)"), new ColumnDesc("SQL_DATA_TYPE", "INT", 14, "Unused"), new ColumnDesc("SQL_DATETIME_SUB", "INT", 15, "Unused"), new ColumnDesc("CHAR_OCTET_LENGTH", "INT", 16, "For char types the maximum number of bytes in the column"), new ColumnDesc("ORDINAL_POSITION", "INT", 17, "Index of column in table (starting at 1)"), new ColumnDesc("IS_NULLABLE", "STRING", 18, "\"NO\" means column definitely does not " + "allow NULL values; \"YES\" means the column might allow NULL values. " + "An empty string means nobody knows."), new ColumnDesc("SCOPE_CATALOG", "STRING", 19, "Catalog of table that is the scope " + "of a reference attribute (null if DATA_TYPE isn't REF)"), new ColumnDesc("SCOPE_SCHEMA", "STRING", 20, "Schema of table that is the scope of a " + "reference attribute (null if the DATA_TYPE isn't REF)"), new ColumnDesc("SCOPE_TABLE", "STRING", 21, "Table name that this the scope " + "of a reference attribure (null if the DATA_TYPE isn't REF)"), new ColumnDesc("SOURCE_DATA_TYPE", "SMALLINT", 22, "Source type of a distinct type " + "or user-generated Ref type, SQL type from java.sql.Types " + "(null if DATA_TYPE isn't DISTINCT or user-generated REF)"), new ColumnDesc("IS_AUTO_INCREMENT", "STRING", 23, "Indicates whether this column is auto incremented."));
// Get all columns
ListenableFuture<ExploreExecutionResult> future = getExploreClient().columns(null, null, "%", "%");
List<QueryResult> expectedColumns = Lists.newArrayList(getExpectedColumns(NAMESPACE_DATABASE));
expectedColumns.addAll(getExpectedColumns(OTHER_NAMESPACE_DATABASE));
assertStatementResult(future, true, expectedColumnDescs, expectedColumns);
// Get all columns in a namespace
future = getExploreClient().columns(null, OTHER_NAMESPACE_ID.getNamespace(), "%", "%");
assertStatementResult(future, true, expectedColumnDescs, getExpectedColumns(OTHER_NAMESPACE_DATABASE));
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class HiveExploreServiceTestRun method testQueriesList.
@Test
public void testQueriesList() throws Exception {
ListenableFuture<ExploreExecutionResult> future;
ExploreExecutionResult results;
List<QueryInfo> queries;
// Use different namespaces than the other tests so that when its run in a suite there isn't a chance of
// stray queries polluting this test
NamespaceId testNamespace1 = new NamespaceId("test1");
NamespaceId testNamespace2 = new NamespaceId("test2");
NamespaceMeta testNamespace1Meta = new NamespaceMeta.Builder().setName(testNamespace1).build();
namespaceAdmin.create(testNamespace1Meta);
NamespaceMeta testNamespace2Meta = new NamespaceMeta.Builder().setName(testNamespace2).build();
namespaceAdmin.create(testNamespace2Meta);
exploreClient.addNamespace(testNamespace1Meta).get();
exploreClient.addNamespace(testNamespace2Meta).get();
exploreClient.submit(testNamespace1, "create table my_table (first INT, second STRING)").get();
future = exploreClient.submit(testNamespace1, "show tables");
future.get();
future = exploreClient.submit(testNamespace2, "show tables");
future.get();
future = exploreClient.submit(testNamespace1, "select * from my_table");
results = future.get();
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(2, queries.size());
Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertTrue(queries.get(0).isActive());
Assert.assertEquals("show tables", queries.get(1).getStatement());
Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
Assert.assertTrue(queries.get(1).isHasResults());
Assert.assertTrue(queries.get(1).isActive());
// Make the last query inactive
while (results.hasNext()) {
results.next();
}
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(2, queries.size());
Assert.assertEquals("select * from my_table", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertFalse(queries.get(0).isActive());
Assert.assertEquals("show tables", queries.get(1).getStatement());
Assert.assertEquals("FINISHED", queries.get(1).getStatus().toString());
Assert.assertTrue(queries.get(1).isHasResults());
Assert.assertTrue(queries.get(1).isActive());
// Close last query
results.close();
queries = exploreService.getQueries(testNamespace1);
Assert.assertEquals(1, queries.size());
Assert.assertEquals("show tables", queries.get(0).getStatement());
queries = exploreService.getQueries(testNamespace2);
Assert.assertEquals(1, queries.size());
Assert.assertEquals("show tables", queries.get(0).getStatement());
Assert.assertEquals("FINISHED", queries.get(0).getStatus().toString());
Assert.assertTrue(queries.get(0).isHasResults());
Assert.assertTrue(queries.get(0).isActive());
// Make sure queries are reverse ordered by timestamp
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
exploreClient.submit(testNamespace1, "show tables").get();
queries = exploreService.getQueries(testNamespace1);
List<Long> timestamps = Lists.newArrayList();
Assert.assertEquals(5, queries.size());
for (QueryInfo queryInfo : queries) {
Assert.assertNotNull(queryInfo.getStatement());
Assert.assertNotNull(queryInfo.getQueryHandle());
Assert.assertTrue(queryInfo.isActive());
Assert.assertEquals("FINISHED", queryInfo.getStatus().toString());
Assert.assertEquals("show tables", queryInfo.getStatement());
timestamps.add(queryInfo.getTimestamp());
}
// verify the ordering
Assert.assertTrue(Ordering.natural().reverse().isOrdered(timestamps));
exploreClient.submit(testNamespace1, "drop table if exists my_table").get();
exploreClient.removeNamespace(testNamespace1).get();
exploreClient.removeNamespace(testNamespace2).get();
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class HiveExploreStructuredRecordTestRun method testInsert.
@Test
public void testInsert() throws Exception {
DatasetId copyTable = NAMESPACE_ID.dataset("emailCopy");
datasetFramework.addInstance(Table.class.getName(), copyTable, TableProperties.builder().setSchema(EmailTableDefinition.SCHEMA).setRowFieldName("id").build());
try {
String command = String.format("insert into %s select * from %s", getDatasetHiveName(copyTable), MY_TABLE_NAME);
ExploreExecutionResult result = exploreClient.submit(NAMESPACE_ID, command).get();
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, result.getStatus().getStatus());
command = String.format("select id, subject, body, sender from %s", getDatasetHiveName(copyTable));
runCommand(NAMESPACE_ID, command, true, Lists.newArrayList(new ColumnDesc("id", "STRING", 1, null), new ColumnDesc("subject", "STRING", 2, null), new ColumnDesc("body", "STRING", 3, null), new ColumnDesc("sender", "STRING", 4, null)), Lists.newArrayList(new QueryResult(Lists.<Object>newArrayList("email1", "this is the subject", "this is the body", "sljackson@boss.com"))));
} finally {
datasetFramework.deleteInstance(copyTable);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class WritableDatasetTestRun method assertSelectAll.
private void assertSelectAll(NamespaceId namespace, String table, List<List<Object>> expectedResults) throws Exception {
ExploreExecutionResult result = exploreClient.submit(namespace, "select * from " + table).get();
for (List<Object> expectedResult : expectedResults) {
Assert.assertEquals(expectedResult, result.next().getColumns());
}
Assert.assertFalse(result.hasNext());
result.close();
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class WritableDatasetTestRun method writeFromAnotherNamespace.
@Test
public void writeFromAnotherNamespace() throws Exception {
datasetFramework.addModule(kvTable, new KeyValueTableDefinition.KeyValueTableModule());
datasetFramework.addInstance("kvTable", simpleTable, DatasetProperties.EMPTY);
datasetFramework.addModule(otherKvTable, new KeyValueTableDefinition.KeyValueTableModule());
datasetFramework.addInstance("kvTable", otherSimpleTable, DatasetProperties.EMPTY);
try {
ExploreExecutionResult result = exploreClient.submit(OTHER_NAMESPACE_ID, "select * from " + simpleTableName).get();
Assert.assertFalse(result.hasNext());
// Accessing dataset instance to perform data operations
KeyValueTableDefinition.KeyValueTable table = datasetFramework.getDataset(simpleTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx = transactionManager.startShort(100);
table.startTx(tx);
table.put(1, "one");
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx.getTransactionId(), tx.getWritePointer());
table.postTxCommit();
String query = String.format("insert into table %s select * from cdap_namespace.%s", otherSimpleTableName, simpleTableName);
exploreClient.submit(OTHER_NAMESPACE_ID, query).get().close();
assertSelectAll(NAMESPACE_ID, simpleTableName, ImmutableList.<List<Object>>of(ImmutableList.<Object>of(1, "one")));
// Write into otherSimpleTable and assert that it doesn't show up in queries over simpleTable
table = datasetFramework.getDataset(otherSimpleTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
tx = transactionManager.startShort(100);
table.startTx(tx);
table.put(2, "two");
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx.getTransactionId(), tx.getWritePointer());
table.postTxCommit();
assertSelectAll(OTHER_NAMESPACE_ID, otherSimpleTableName, ImmutableList.<List<Object>>of(ImmutableList.<Object>of(1, "one"), ImmutableList.<Object>of(2, "two")));
assertSelectAll(NAMESPACE_ID, simpleTableName, ImmutableList.<List<Object>>of(ImmutableList.<Object>of(1, "one")));
} finally {
datasetFramework.deleteInstance(simpleTable);
datasetFramework.deleteInstance(otherSimpleTable);
datasetFramework.deleteModule(kvTable);
datasetFramework.deleteModule(otherKvTable);
}
}
Aggregations