use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class WritableDatasetTestRun method writeIntoNonScannableDataset.
@Test
public void writeIntoNonScannableDataset() throws Exception {
DatasetId writableTable = NAMESPACE_ID.dataset("writable_table");
String writableTableName = getDatasetHiveName(writableTable);
datasetFramework.addModule(keyExtendedStructValueTable, new KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTableModule());
datasetFramework.addInstance("keyExtendedStructValueTable", extendedTable, DatasetProperties.EMPTY);
datasetFramework.addModule(writableKeyStructValueTable, new WritableKeyStructValueTableDefinition.KeyStructValueTableModule());
datasetFramework.addInstance("writableKeyStructValueTable", writableTable, DatasetProperties.EMPTY);
try {
// Accessing dataset instance to perform data operations
KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTable table = datasetFramework.getDataset(extendedTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx1 = transactionManager.startShort(100);
table.startTx(tx1);
KeyExtendedStructValueTableDefinition.KeyExtendedValue value1 = new KeyExtendedStructValueTableDefinition.KeyExtendedValue("10", new KeyStructValueTableDefinition.KeyValue.Value("ten", Lists.newArrayList(10, 11, 12)), 20);
table.put("10", value1);
Assert.assertEquals(value1, table.get("10"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx1.getTransactionId(), tx1.getWritePointer());
table.postTxCommit();
String query = "insert into table " + writableTableName + " select key,value from " + extendedTableName;
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(NAMESPACE_ID, query);
ExploreExecutionResult result = future.get();
result.close();
KeyStructValueTableDefinition.KeyStructValueTable table2 = datasetFramework.getDataset(writableTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx = transactionManager.startShort(100);
Assert.assertNotNull(table2);
table2.startTx(tx);
Assert.assertEquals(new KeyStructValueTableDefinition.KeyValue.Value("ten", Lists.newArrayList(10, 11, 12)), table2.get("10_2"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx.getTransactionId(), tx.getWritePointer());
table.postTxCommit();
} finally {
datasetFramework.deleteInstance(writableTable);
datasetFramework.deleteInstance(extendedTable);
datasetFramework.deleteModule(writableKeyStructValueTable);
datasetFramework.deleteModule(keyExtendedStructValueTable);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
the class WritableDatasetTestRun method multipleInsertsTest.
@Test
public void multipleInsertsTest() throws Exception {
DatasetId myTable1 = NAMESPACE_ID.dataset("my_table_1");
DatasetId myTable2 = NAMESPACE_ID.dataset("my_table_2");
DatasetId myTable3 = NAMESPACE_ID.dataset("my_table_3");
String myTable1HiveName = getDatasetHiveName(myTable1);
String myTable2HiveName = getDatasetHiveName(myTable2);
String myTable3HiveName = getDatasetHiveName(myTable3);
try {
initKeyValueTable(MY_TABLE, true);
initKeyValueTable(myTable1, false);
initKeyValueTable(myTable2, false);
initKeyValueTable(myTable3, false);
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(NAMESPACE_ID, String.format("from %s insert into table %s select * where key='1' " + "insert into table %s select * where key='2' " + "insert into table %s select *", MY_TABLE_NAME, myTable1HiveName, myTable2HiveName, myTable3HiveName));
ExploreExecutionResult result = future.get();
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable2HiveName).get();
Assert.assertEquals("2_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable1HiveName).get();
Assert.assertEquals("1_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + myTable3HiveName).get();
Assert.assertEquals("1_2", result.next().getColumns().get(0).toString());
Assert.assertEquals("2_2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
} finally {
datasetFramework.deleteInstance(MY_TABLE);
datasetFramework.deleteInstance(myTable1);
datasetFramework.deleteInstance(myTable2);
datasetFramework.deleteInstance(myTable3);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by cdapio.
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);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class WritableDatasetTestRun method writeIntoOtherDatasetTest.
@Test
public void writeIntoOtherDatasetTest() throws Exception {
datasetFramework.addModule(keyExtendedStructValueTable, new KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTableModule());
datasetFramework.addInstance("keyExtendedStructValueTable", extendedTable, DatasetProperties.EMPTY);
try {
initKeyValueTable(MY_TABLE, true);
// Accessing dataset instance to perform data operations
KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTable table = datasetFramework.getDataset(extendedTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx1 = transactionManager.startShort(100);
table.startTx(tx1);
KeyExtendedStructValueTableDefinition.KeyExtendedValue value1 = new KeyExtendedStructValueTableDefinition.KeyExtendedValue("10", new KeyStructValueTableDefinition.KeyValue.Value("ten", Lists.newArrayList(10, 11, 12)), 20);
table.put("10", value1);
Assert.assertEquals(value1, table.get("10"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx1.getTransactionId(), tx1.getWritePointer());
table.postTxCommit();
String query = String.format("insert into table %s select key,value from %s", MY_TABLE_NAME, extendedTableName);
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(NAMESPACE_ID, query);
ExploreExecutionResult result = future.get();
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + MY_TABLE_NAME).get();
Assert.assertEquals("1", result.next().getColumns().get(0).toString());
Assert.assertEquals("10_2", result.next().getColumns().get(0).toString());
Assert.assertEquals("2", result.next().getColumns().get(0).toString());
Assert.assertFalse(result.hasNext());
result.close();
// Test insert overwrite
query = String.format("insert overwrite table %s select key,value from %s", MY_TABLE_NAME, extendedTableName);
result = exploreClient.submit(NAMESPACE_ID, query).get();
result.close();
result = exploreClient.submit(NAMESPACE_ID, "select * from " + MY_TABLE_NAME).get();
result.hasNext();
} finally {
datasetFramework.deleteInstance(MY_TABLE);
datasetFramework.deleteInstance(extendedTable);
datasetFramework.deleteModule(keyExtendedStructValueTable);
}
}
use of io.cdap.cdap.explore.client.ExploreExecutionResult in project cdap by caskdata.
the class WritableDatasetTestRun method writeIntoNonScannableDataset.
@Test
public void writeIntoNonScannableDataset() throws Exception {
DatasetId writableTable = NAMESPACE_ID.dataset("writable_table");
String writableTableName = getDatasetHiveName(writableTable);
datasetFramework.addModule(keyExtendedStructValueTable, new KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTableModule());
datasetFramework.addInstance("keyExtendedStructValueTable", extendedTable, DatasetProperties.EMPTY);
datasetFramework.addModule(writableKeyStructValueTable, new WritableKeyStructValueTableDefinition.KeyStructValueTableModule());
datasetFramework.addInstance("writableKeyStructValueTable", writableTable, DatasetProperties.EMPTY);
try {
// Accessing dataset instance to perform data operations
KeyExtendedStructValueTableDefinition.KeyExtendedStructValueTable table = datasetFramework.getDataset(extendedTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx1 = transactionManager.startShort(100);
table.startTx(tx1);
KeyExtendedStructValueTableDefinition.KeyExtendedValue value1 = new KeyExtendedStructValueTableDefinition.KeyExtendedValue("10", new KeyStructValueTableDefinition.KeyValue.Value("ten", Lists.newArrayList(10, 11, 12)), 20);
table.put("10", value1);
Assert.assertEquals(value1, table.get("10"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx1.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx1.getTransactionId(), tx1.getWritePointer());
table.postTxCommit();
String query = "insert into table " + writableTableName + " select key,value from " + extendedTableName;
ListenableFuture<ExploreExecutionResult> future = exploreClient.submit(NAMESPACE_ID, query);
ExploreExecutionResult result = future.get();
result.close();
KeyStructValueTableDefinition.KeyStructValueTable table2 = datasetFramework.getDataset(writableTable, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
Transaction tx = transactionManager.startShort(100);
Assert.assertNotNull(table2);
table2.startTx(tx);
Assert.assertEquals(new KeyStructValueTableDefinition.KeyValue.Value("ten", Lists.newArrayList(10, 11, 12)), table2.get("10_2"));
Assert.assertTrue(table.commitTx());
transactionManager.canCommit(tx.getTransactionId(), table.getTxChanges());
transactionManager.commit(tx.getTransactionId(), tx.getWritePointer());
table.postTxCommit();
} finally {
datasetFramework.deleteInstance(writableTable);
datasetFramework.deleteInstance(extendedTable);
datasetFramework.deleteModule(writableKeyStructValueTable);
datasetFramework.deleteModule(keyExtendedStructValueTable);
}
}
Aggregations