Search in sources :

Example 1 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class AccumuloUpdateExecution method createBatchWriter.

private BatchWriter createBatchWriter(Table table, Connector connector) throws TranslatorException, TableNotFoundException {
    String tableName = SQLStringVisitor.getRecordName(table);
    BatchWriter writer;
    try {
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    } catch (TableNotFoundException e) {
        try {
            connector.tableOperations().create(tableName, true, TimeType.LOGICAL);
        } catch (AccumuloException e1) {
            throw new TranslatorException(e1);
        } catch (AccumuloSecurityException e1) {
            throw new TranslatorException(e1);
        } catch (TableExistsException e1) {
            throw new TranslatorException(e1);
        }
        writer = connector.createBatchWriter(tableName, new BatchWriterConfig());
    }
    return writer;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) TranslatorException(org.teiid.translator.TranslatorException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter)

Example 2 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class AccumuloUpdateExecution method getRowId.

private byte[] getRowId(List<ColumnReference> columns, List<Expression> values) throws TranslatorException {
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i).getMetadataObject();
        String rowId = SQLStringVisitor.getRecordName(column);
        if (rowId.equalsIgnoreCase(AccumuloMetadataProcessor.ROWID) || AccumuloQueryVisitor.isPartOfPrimaryKey(column)) {
            Object value = values.get(i);
            if (value instanceof Literal) {
                return AccumuloDataTypeManager.serialize(((Literal) value).getValue());
            }
            throw new TranslatorException(AccumuloPlugin.Event.TEIID19006, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19006));
        }
    }
    return null;
}
Also used : Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) TranslatorException(org.teiid.translator.TranslatorException)

Example 3 with TranslatorException

use of org.teiid.translator.TranslatorException 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 4 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class SimpleDBConnectionImpl method performSelect.

/**
 * Performs select expression. This expression must be in format which is understandable to SimpleDB database
 * @param selectExpression
 * @param columns
 * @return Iterator of List<String> results
 */
@Override
public SelectResult performSelect(String selectExpression, String nextToken) throws TranslatorException {
    try {
        SelectRequest selectRequest = new SelectRequest(selectExpression);
        if (nextToken != null) {
            selectRequest.setNextToken(nextToken);
        }
        selectRequest.setConsistentRead(true);
        return client.select(selectRequest);
    } catch (AmazonServiceException e) {
        throw new TranslatorException(e);
    } catch (AmazonClientException e) {
        throw new TranslatorException(e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) AmazonServiceException(com.amazonaws.AmazonServiceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 5 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class SimpleDBConnectionImpl method performUpdate.

/**
 *  Performs update on given domain and items
 * @param domainName
 * @param items
 */
@Override
public int performUpdate(String domainName, Map<String, Object> updateAttributes, String selectExpression) throws TranslatorException {
    try {
        List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
        for (Map.Entry<String, Object> column : updateAttributes.entrySet()) {
            addAttribute(column.getKey(), column.getValue(), attributes);
        }
        List<ReplaceableItem> updateItems = new ArrayList<ReplaceableItem>();
        int count = 0;
        String nextToken = null;
        do {
            SelectResult result = performSelect(selectExpression, nextToken);
            nextToken = result.getNextToken();
            Iterator<Item> iter = result.getItems().iterator();
            while (iter.hasNext()) {
                Item item = iter.next();
                updateItems.add(new ReplaceableItem(item.getName(), attributes));
                count++;
                if (count % 25 == 0) {
                    executeBatch(domainName, updateItems);
                    updateItems.clear();
                }
            }
            executeBatch(domainName, updateItems);
        } while (nextToken != null);
        return count;
    } catch (AmazonServiceException e) {
        throw new TranslatorException(e);
    } catch (AmazonClientException e) {
        throw new TranslatorException(e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) TranslatorException(org.teiid.translator.TranslatorException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10