Search in sources :

Example 41 with Put

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");
}
Also used : Table(io.cdap.cdap.api.dataset.table.Table) TxRunnable(io.cdap.cdap.api.TxRunnable) StageStatistics(io.cdap.cdap.etl.api.condition.StageStatistics) DatasetContext(io.cdap.cdap.api.data.DatasetContext) Put(io.cdap.cdap.api.dataset.table.Put)

Example 42 with Put

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);
}
Also used : MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) Put(io.cdap.cdap.api.dataset.table.Put)

Example 43 with 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);
        }
    }
}
Also used : InvertedValueIndexer(io.cdap.cdap.data2.metadata.indexer.InvertedValueIndexer) Indexer(io.cdap.cdap.data2.metadata.indexer.Indexer) SchemaIndexer(io.cdap.cdap.data2.metadata.indexer.SchemaIndexer) DefaultValueIndexer(io.cdap.cdap.data2.metadata.indexer.DefaultValueIndexer) MetadataEntityTypeIndexer(io.cdap.cdap.data2.metadata.indexer.MetadataEntityTypeIndexer) ValueOnlyIndexer(io.cdap.cdap.data2.metadata.indexer.ValueOnlyIndexer) InvertedTimeIndexer(io.cdap.cdap.data2.metadata.indexer.InvertedTimeIndexer) MDSKey(io.cdap.cdap.data2.dataset2.lib.table.MDSKey) Put(io.cdap.cdap.api.dataset.table.Put)

Example 44 with 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);
    }
}
Also used : DataSetException(io.cdap.cdap.api.dataset.DataSetException) IOException(java.io.IOException) Put(io.cdap.cdap.api.dataset.table.Put) WriteOnly(io.cdap.cdap.api.annotation.WriteOnly)

Example 45 with Put

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);
}
Also used : Table(io.cdap.cdap.api.dataset.table.Table) Transaction(org.apache.tephra.Transaction) TransactionAware(org.apache.tephra.TransactionAware) Put(io.cdap.cdap.api.dataset.table.Put)

Aggregations

Put (io.cdap.cdap.api.dataset.table.Put)53 Test (org.junit.Test)24 Table (io.cdap.cdap.api.dataset.table.Table)23 Get (io.cdap.cdap.api.dataset.table.Get)13 Row (io.cdap.cdap.api.dataset.table.Row)13 Transaction (org.apache.tephra.Transaction)13 TransactionAware (org.apache.tephra.TransactionAware)13 Schema (io.cdap.cdap.api.data.schema.Schema)10 TransactionExecutor (org.apache.tephra.TransactionExecutor)10 DatasetAdmin (io.cdap.cdap.api.dataset.DatasetAdmin)7 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)6 IOException (java.io.IOException)6 HBaseTable (io.cdap.cdap.data2.dataset2.lib.table.hbase.HBaseTable)5 DatasetId (io.cdap.cdap.proto.id.DatasetId)5 WriteOnly (io.cdap.cdap.api.annotation.WriteOnly)4 DataSetException (io.cdap.cdap.api.dataset.DataSetException)4 Scanner (io.cdap.cdap.api.dataset.table.Scanner)4 MDSKey (io.cdap.cdap.data2.dataset2.lib.table.MDSKey)4 ReflectionPutWriter (io.cdap.cdap.internal.io.ReflectionPutWriter)4 Map (java.util.Map)4