Search in sources :

Example 1 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class AccumuloUpdateExecution method performInsert.

private void performInsert(Insert insert) throws TranslatorException, TableNotFoundException, MutationsRejectedException {
    Table table = insert.getTable().getMetadataObject();
    this.updateCount = 0;
    Connector connector = this.connection.getInstance();
    BatchWriter writer = createBatchWriter(table, connector);
    List<ColumnReference> columns = insert.getColumns();
    if (insert.getParameterValues() == null) {
        List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
        writeMutation(writer, columns, values);
        this.updateCount++;
    } else {
        int batchSize = this.executionContext.getBatchSize();
        // bulk insert; should help
        Iterator<? extends List<Expression>> args = (Iterator<? extends List<Expression>>) insert.getParameterValues();
        while (args.hasNext()) {
            List<Expression> values = args.next();
            writeMutation(writer, columns, values);
            this.updateCount++;
            if ((this.updateCount % batchSize) == 0) {
                writer.close();
                writer = createBatchWriter(table, connector);
            }
        }
    }
    // write the mutation
    writer.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Table(org.teiid.metadata.Table) Expression(org.teiid.language.Expression) Iterator(java.util.Iterator) List(java.util.List) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 2 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class AccumuloUpdateExecution method performDelete.

private void performDelete(Delete delete) throws TableNotFoundException, MutationsRejectedException, TranslatorException {
    if (delete.getParameterValues() != null) {
        throw new TranslatorException(AccumuloPlugin.Event.TEIID19005, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19005));
    }
    Table table = delete.getTable().getMetadataObject();
    AccumuloQueryVisitor visitor = new AccumuloQueryVisitor(this.aef);
    visitor.visitNode(delete.getWhere());
    if (!visitor.exceptions.isEmpty()) {
        throw visitor.exceptions.get(0);
    }
    /*
		// To get the update count I am taking longer route..
		Connector connector = this.connection.getInstance();
		BatchDeleter deleter = connector.createBatchDeleter(SQLStringVisitor.getRecordName(table), auths, this.aef.getQueryThreadsCount(), new BatchWriterConfig());	        	
		deleter.setRanges(visitor.getRanges());
		deleter.delete();
		deleter.close();
		*/
    Text prevRow = null;
    Connector connector = this.connection.getInstance();
    BatchWriter writer = createBatchWriter(table, connector);
    Iterator<Entry<Key, Value>> results = AccumuloQueryExecution.runQuery(this.aef, this.connection.getInstance(), this.connection.getAuthorizations(), visitor.getRanges(), table, null);
    while (results.hasNext()) {
        Key key = results.next().getKey();
        Text rowId = key.getRow();
        if (prevRow == null || !prevRow.equals(rowId)) {
            this.updateCount++;
        }
        prevRow = rowId;
        Mutation mutation = new Mutation(rowId);
        mutation.putDelete(key.getColumnFamily(), key.getColumnQualifier());
        writer.addMutation(mutation);
    }
    writer.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Entry(java.util.Map.Entry) Table(org.teiid.metadata.Table) TranslatorException(org.teiid.translator.TranslatorException) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key)

Example 3 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestCouchbaseMetadataProcessor method testComplexJson.

@Test
public void testComplexJson() throws ResourceException {
    CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "couchbase", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    Table table = createTable(mf, KEYSPACE, KEYSPACE);
    mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, complexJson(), mf, table, KEYSPACE, false, new Dimension());
    helpTest("complexJson.expected", mf);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) CouchbaseMetadataProcessor(org.teiid.translator.couchbase.CouchbaseMetadataProcessor) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) CouchbaseProperties(org.teiid.translator.couchbase.CouchbaseProperties) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestCouchbaseMetadataProcessor method testCustomerOrderWithTypedName.

@Test
public void testCustomerOrderWithTypedName() throws ResourceException {
    CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
    mp.setTypeNameList("`test`:`type`,`beer-sample`:`type`,` travel-sample`:`type`");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "couchbase", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    Table customer = createTable(mf, KEYSPACE, "Customer");
    mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
    Table order = createTable(mf, KEYSPACE, "Oder");
    mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
    helpTest("customerOrderTypedName.expected", mf);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) CouchbaseMetadataProcessor(org.teiid.translator.couchbase.CouchbaseMetadataProcessor) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) CouchbaseProperties(org.teiid.translator.couchbase.CouchbaseProperties) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestCouchbaseMetadataProcessor method testJsonNestedArray.

@Test
public void testJsonNestedArray() throws ResourceException {
    CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "couchbase", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    Table table = createTable(mf, KEYSPACE, KEYSPACE);
    mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, complexJsonNestedArray(), mf, table, KEYSPACE, false, new Dimension());
    helpTest("complexJsonNestedArray.expected", mf);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) CouchbaseMetadataProcessor(org.teiid.translator.couchbase.CouchbaseMetadataProcessor) Dimension(org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension) CouchbaseProperties(org.teiid.translator.couchbase.CouchbaseProperties) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Table (org.teiid.metadata.Table)239 Test (org.junit.Test)82 Column (org.teiid.metadata.Column)72 MetadataFactory (org.teiid.metadata.MetadataFactory)59 Properties (java.util.Properties)45 MetadataStore (org.teiid.metadata.MetadataStore)37 Schema (org.teiid.metadata.Schema)35 TranslatorException (org.teiid.translator.TranslatorException)30 ArrayList (java.util.ArrayList)27 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)27 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)23 List (java.util.List)22 ForeignKey (org.teiid.metadata.ForeignKey)22 Connection (java.sql.Connection)15 QueryNode (org.teiid.query.mapping.relational.QueryNode)15 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)15 KeyRecord (org.teiid.metadata.KeyRecord)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)13 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)13