Search in sources :

Example 36 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TestInsertProcessing method testInsertTriggerWithTypeChanges.

@Test
public void testInsertTriggerWithTypeChanges() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("CREATE FOREIGN TABLE SmallA (IntKey integer PRIMARY KEY,         StringKey string,         IntNum integer,         StringNum string,         FloatNum float,         LongNum bigint,         DoubleNum double,         ByteNum smallint,         DateValue date,         TimeValue time,         TimestampValue timestamp,         BooleanValue boolean,         CharValue char(1),         ShortValue smallint,         BigIntegerValue decimal,         BigDecimalValue decimal,         ObjectValue blob)     OPTIONS (UPDATABLE 'TRUE'); " + " CREATE VIEW SmallAV (IntKey integer PRIMARY KEY,     StringKey string,     IntNum integer,     StringNum string,     FloatNum float,     LongNum long,     DoubleNum double,     ByteNum byte,     DateValue date,     TimeValue time,     TimestampValue timestamp,     BooleanValue boolean,     CharValue char,     ShortValue short,     BigIntegerValue biginteger,     BigDecimalValue bigdecimal,     ObjectValue object) OPTIONS (UPDATABLE 'TRUE') AS SELECT IntKey, StringKey, IntNum,     StringNum, FloatNum, LongNum, DoubleNum,     convert(ByteNum, byte) AS ByteNum, DateValue, TimeValue, TimestampValue,     BooleanValue, CharValue, ShortValue,     convert(BigIntegerValue, biginteger) AS BigIntegerValue, BigDecimalValue,     convert(ObjectValue, object) AS ObjectValue FROM SmallA; " + " CREATE TRIGGER ON SmallAV INSTEAD OF INSERT AS FOR EACH ROW BEGIN ATOMIC     INSERT INTO smalla (IntKey, StringKey, IntNum, StringNum, FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue, BigIntegerValue, BigDecimalValue, ObjectValue) VALUES         (NEW.IntKey, NEW.StringKey, NEW.IntNum, NEW.StringNum, NEW.FloatNum, NEW.LongNum, NEW.DoubleNum, NEW.ByteNum, NEW.DateValue, NEW.TimeValue, NEW.TimestampValue,         NEW.BooleanValue, NEW.CharValue, NEW.ShortValue, NEW.BigIntegerValue, NEW.BigDecimalValue, to_bytes(convert(NEW.ObjectValue, string), 'UTF-8')); END;", "x", "y");
    // $NON-NLS-1$
    String sql = "INSERT INTO smallav (IntKey, IntNum) VALUES (1, null), (2, 2)";
    List<?>[] expected = new List[] { Arrays.asList(1) };
    final List[] secondResult = new List[] { Arrays.asList(2, null, 2, null, null, null, null, null, null, null, null, null, null, null, null, null, null) };
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            TupleSource ts = ((Insert) command).getTupleSource();
            try {
                List<?> tuple = ts.nextTuple();
                assertEquals(Arrays.asList(1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), tuple);
                tuple = ts.nextTuple();
                assertEquals(secondResult[0], tuple);
                assertNull(ts.nextTuple());
            } catch (TeiidProcessingException e) {
                throw new TeiidRuntimeException(e);
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    dataManager.addData("INSERT INTO smalla (IntKey, StringKey, IntNum, StringNum, FloatNum, LongNum, DoubleNum, ByteNum, DateValue, TimeValue, TimestampValue, BooleanValue, CharValue, ShortValue, BigIntegerValue, BigDecimalValue, ObjectValue) VALUES (...)", Arrays.asList(2));
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.INSERT_WITH_ITERATOR, true);
    ProcessorPlan plan = helpGetPlan(sql, tm, new DefaultCapabilitiesFinder(bsc));
    helpProcess(plan, dataManager, expected);
    sql = "INSERT INTO smallav (IntKey, CharValue) VALUES (1, null), (2, convert('+', char))";
    plan = helpGetPlan(sql, tm, new DefaultCapabilitiesFinder(bsc));
    secondResult[0] = Arrays.asList(2, null, null, null, null, null, null, null, null, null, null, null, '+', null, null, null, null);
    helpProcess(plan, dataManager, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Insert(org.teiid.query.sql.lang.Insert) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TupleSource(org.teiid.common.buffer.TupleSource) List(java.util.List) Test(org.junit.Test)

Example 37 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class GlobalTableStoreImpl method setState.

@Override
public void setState(String stateId, InputStream istream) {
    try {
        ObjectInputStream ois = new ObjectInputStream(istream);
        loadTable(stateId, ois);
        ois.close();
    } catch (Exception e) {
        MatTableInfo info = this.getMatTableInfo(stateId);
        if (!info.isUpToDate()) {
            info.setState(MatState.FAILED_LOAD, null);
        }
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30222, e);
    }
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 38 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class GlobalTableStoreImpl method getState.

@Override
public void getState(String stateId, OutputStream ostream) {
    try {
        ObjectOutputStream oos = new ObjectOutputStream(ostream);
        sendTable(stateId, oos, false);
        oos.close();
    } catch (IOException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30220, e);
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30221, e);
    }
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 39 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TempTable method clone.

public TempTable clone() {
    lock.readLock().lock();
    try {
        TempTable clone = (TempTable) super.clone();
        clone.lock = new ReentrantReadWriteLock();
        if (clone.indexTables != null) {
            clone.indexTables = new LinkedHashMap<List<ElementSymbol>, TempTable>(clone.indexTables);
            for (Map.Entry<List<ElementSymbol>, TempTable> entry : clone.indexTables.entrySet()) {
                TempTable indexClone = entry.getValue().clone();
                indexClone.lock = clone.lock;
                entry.setValue(indexClone);
            }
        }
        clone.tree = tree.clone();
        clone.activeReaders = new AtomicInteger();
        return clone;
    } catch (CloneNotSupportedException e) {
        throw new TeiidRuntimeException(e);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SetClauseList(org.teiid.query.sql.lang.SetClauseList) List(java.util.List) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 40 with TeiidRuntimeException

use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.

the class TestValidator method helpResolve.

// ################################## TEST HELPERS ################################
static Command helpResolve(String sql, QueryMetadataInterface metadata) {
    Command command = null;
    try {
        command = QueryParser.getQueryParser().parseCommand(sql);
        QueryResolver.resolveCommand(command, metadata);
    } catch (Exception e) {
        throw new TeiidRuntimeException(e);
    }
    return command;
}
Also used : Command(org.teiid.query.sql.lang.Command) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryParserException(org.teiid.api.exception.query.QueryParserException) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) QueryResolverException(org.teiid.api.exception.query.QueryResolverException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException)

Aggregations

TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)103 IOException (java.io.IOException)27 TeiidComponentException (org.teiid.core.TeiidComponentException)22 TeiidException (org.teiid.core.TeiidException)22 ArrayList (java.util.ArrayList)20 TeiidProcessingException (org.teiid.core.TeiidProcessingException)17 SQLException (java.sql.SQLException)11 ObjectInputStream (java.io.ObjectInputStream)9 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 Map (java.util.Map)7 Test (org.junit.Test)7 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)7 ObjectOutputStream (java.io.ObjectOutputStream)6 List (java.util.List)6 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 JsonObject (com.couchbase.client.java.document.json.JsonObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4