use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class MockCondition method apply.
@Override
public boolean apply(final ConditionContext context) throws Exception {
String propertyName = config.name + ".branch.to.execute";
String propertyValue = context.getArguments().get(propertyName);
// write stage statistics if table name is provided
if (config.tableName != null) {
context.execute(new TxRunnable() {
@Override
public void run(DatasetContext datasetContext) throws Exception {
Table table = datasetContext.getDataset(config.tableName);
for (Map.Entry<String, StageStatistics> entry : context.getStageStatistics().entrySet()) {
String stageName = entry.getKey();
StageStatistics statistics = entry.getValue();
Put put = new Put("stats");
put.add(stageName + ".input.records", String.valueOf(statistics.getInputRecordsCount()));
put.add(stageName + ".output.records", String.valueOf(statistics.getOutputRecordsCount()));
put.add(stageName + ".error.records", String.valueOf(statistics.getErrorRecordsCount()));
table.put(put);
}
}
});
}
return propertyValue != null && propertyValue.equals("true");
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class MetadataDataset method writeValue.
private void writeValue(MetadataEntry entry) {
String key = entry.getKey();
MDSKey mdsValueKey = MetadataKey.createValueRowKey(entry.getMetadataEntity(), key);
Put put = new Put(mdsValueKey.getKey());
// add the metadata value
put.add(Bytes.toBytes(VALUE_COLUMN), Bytes.toBytes(entry.getValue()));
indexedTable.put(put);
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class MetadataDataset method storeIndexes.
/**
* Store indexes for a {@link MetadataEntry}
* @param indexers {@link Set<String>} of {@link Indexer indexers} for this {@link MetadataEntry}
* @param metadataEntry {@link MetadataEntry} for which indexes are to be stored
*/
private void storeIndexes(MetadataEntry metadataEntry, Set<Indexer> indexers) {
// Delete existing indexes for metadataEntity-key
deleteIndexes(metadataEntry.getMetadataEntity(), metadataEntry.getKey());
String namespacePrefix = metadataEntry.getMetadataEntity().getValue(MetadataEntity.NAMESPACE) + MetadataConstants.KEYVALUE_SEPARATOR;
for (Indexer indexer : indexers) {
Set<String> indexes = indexer.getIndexes(metadataEntry);
IndexColumn indexColumn = getIndexColumn(metadataEntry.getKey(), indexer.getSortOrder());
for (String index : indexes) {
if (index.isEmpty()) {
continue;
}
// store one value for within namespace search and one for cross namespace search
String lowercaseIndex = index.toLowerCase();
MDSKey mdsIndexKey = MetadataKey.createIndexRowKey(metadataEntry.getMetadataEntity(), metadataEntry.getKey(), lowercaseIndex);
Put put = new Put(mdsIndexKey.getKey());
put.add(Bytes.toBytes(indexColumn.getCrossNamespaceColumn()), Bytes.toBytes(lowercaseIndex));
put.add(Bytes.toBytes(indexColumn.getColumn()), Bytes.toBytes(namespacePrefix + lowercaseIndex));
indexedTable.put(put);
}
}
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class ObjectMappedTableDataset method write.
@WriteOnly
@Override
public void write(byte[] key, T object) {
Put put = new Put(key);
try {
putWriter.write(object, put);
table.put(put);
} catch (IOException e) {
// should never happen
throw new DataSetException("Failed to encode object to be written: " + e.getMessage(), e);
}
}
use of io.cdap.cdap.api.dataset.table.Put in project cdap by caskdata.
the class HiveExploreTableTestRun method setupTable.
private void setupTable(@Nullable String dbName, @Nullable String tableName) throws Exception {
if (dbName != null) {
runCommand(NAMESPACE_ID, "create database if not exists " + dbName, false, null, null);
}
datasetFramework.addInstance(Table.class.getName(), MY_TABLE, setupTableProperties(dbName, tableName, SCHEMA));
// Accessing dataset instance to perform data operations
Table table = datasetFramework.getDataset(MY_TABLE, DatasetDefinition.NO_ARGUMENTS, null);
Assert.assertNotNull(table);
TransactionAware txTable = (TransactionAware) table;
Transaction tx1 = transactionManager.startShort(100);
txTable.startTx(tx1);
Put put = new Put(Bytes.toBytes("row1"));
put.add("bool_field", false);
put.add("int_field", Integer.MAX_VALUE);
put.add("long_field", Long.MAX_VALUE);
put.add("float_field", 3.14f);
put.add("double_field", 3.14);
put.add("bytes_field", new byte[] { 'A', 'B', 'C' });
table.put(put);
Assert.assertTrue(txTable.commitTx());
transactionManager.canCommit(tx1.getTransactionId(), txTable.getTxChanges());
transactionManager.commit(tx1.getTransactionId(), tx1.getWritePointer());
txTable.postTxCommit();
Transaction tx2 = transactionManager.startShort(100);
txTable.startTx(tx2);
}
Aggregations