Search in sources :

Example 16 with ColumnReference

use of org.teiid.language.ColumnReference in project teiid by teiid.

the class TranslationHelper method helpTestTempTable.

public static String helpTestTempTable(JDBCExecutionFactory transaltor, boolean transactional) throws QueryMetadataException, TeiidComponentException {
    List<ColumnReference> cols = new ArrayList<ColumnReference>();
    cols.add(new ColumnReference(null, "COL1", RealMetadataFactory.exampleBQTCached().getElementID("BQT1.SMALLA.INTKEY"), TypeFacility.RUNTIME_TYPES.INTEGER));
    cols.add(new ColumnReference(null, "COL2", RealMetadataFactory.exampleBQTCached().getElementID("BQT1.SMALLA.STRINGKEY"), TypeFacility.RUNTIME_TYPES.STRING));
    return transaltor.getCreateTempTableSQL("foo", cols, transactional);
}
Also used : ArrayList(java.util.ArrayList) ColumnReference(org.teiid.language.ColumnReference)

Example 17 with ColumnReference

use of org.teiid.language.ColumnReference in project teiid by teiid.

the class TestExtractFunctionModifier method test12.

public void test12() throws Exception {
    // $NON-NLS-1$
    NamedTable group = LANG_FACTORY.createNamedTable("group", null, null);
    // $NON-NLS-1$
    ColumnReference elem = LANG_FACTORY.createColumnReference("col", group, null, TypeFacility.RUNTIME_TYPES.DATE);
    // $NON-NLS-1$
    helpTestMod(elem, "(EXTRACT(DOW FROM group.col) + 1)", SourceSystemFunctions.DAYOFWEEK);
}
Also used : NamedTable(org.teiid.language.NamedTable) ColumnReference(org.teiid.language.ColumnReference)

Example 18 with ColumnReference

use of org.teiid.language.ColumnReference in project teiid by teiid.

the class PhoenixExecutionFactory method translateCommand.

@Override
public List<?> translateCommand(Command command, ExecutionContext context) {
    if (command instanceof SetQuery) {
        SetQuery set = (SetQuery) command;
        if (!set.isAll()) {
            // distinct is not supported, convert to an inline view and add distinct
            Select s = new Select();
            s.setDistinct(true);
            s.setDerivedColumns(new ArrayList<DerivedColumn>());
            s.setOrderBy(set.getOrderBy());
            for (DerivedColumn dc : set.getProjectedQuery().getDerivedColumns()) {
                // it's expected that the columns will be aliases
                Assertion.assertTrue(dc.getAlias() != null);
                ColumnReference cr = new ColumnReference(null, dc.getAlias(), null, dc.getExpression().getType());
                s.getDerivedColumns().add(new DerivedColumn(null, cr));
            }
            set.setOrderBy(null);
            s.setLimit(set.getLimit());
            set.setLimit(null);
            set.setAll(true);
            // $NON-NLS-1$
            s.setFrom(Arrays.asList((TableReference) new DerivedTable(set, "x")));
            return Arrays.asList(s);
        }
    }
    return super.translateCommand(command, context);
}
Also used : TableReference(org.teiid.language.TableReference) SetQuery(org.teiid.language.SetQuery) DerivedTable(org.teiid.language.DerivedTable) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ColumnReference(org.teiid.language.ColumnReference)

Example 19 with ColumnReference

use of org.teiid.language.ColumnReference in project teiid by teiid.

the class TestBulkInsertExecution method testFlowAndErrorReturn.

@Test
public void testFlowAndErrorReturn() throws Exception {
    NamedTable table = new NamedTable("temp", null, Mockito.mock(Table.class));
    ArrayList<ColumnReference> elements = new ArrayList<ColumnReference>();
    elements.add(new ColumnReference(table, "one", Mockito.mock(Column.class), Integer.class));
    elements.add(new ColumnReference(table, "two", Mockito.mock(Column.class), String.class));
    List<Expression> values = new ArrayList<Expression>();
    Parameter param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    param.setValueIndex(0);
    values.add(param);
    param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.STRING);
    param.setValueIndex(1);
    values.add(param);
    ExpressionValueSource valueSource = new ExpressionValueSource(values);
    Insert insert = new Insert(table, elements, valueSource);
    insert.setParameterValues(Arrays.asList(Arrays.asList(2, '2'), Arrays.asList(2, '2'), Arrays.asList(3, '3')).iterator());
    Result r1 = Mockito.mock(Result.class);
    Result r2 = Mockito.mock(Result.class);
    Result r3 = Mockito.mock(Result.class);
    Mockito.when(r1.isSuccess()).thenReturn(true);
    Mockito.when(r1.isCreated()).thenReturn(true);
    Mockito.when(r2.isSuccess()).thenReturn(true);
    Mockito.when(r2.isCreated()).thenReturn(true);
    Mockito.when(r3.isSuccess()).thenReturn(false);
    Mockito.when(r3.isCreated()).thenReturn(false);
    com.sforce.async.Error error = new com.sforce.async.Error();
    error.setMessage("failed, check your data");
    error.setStatusCode(StatusCode.CANNOT_DISABLE_LAST_ADMIN);
    Mockito.when(r3.getErrors()).thenReturn(new Error[] { error });
    BatchResult batchResult = Mockito.mock(BatchResult.class);
    Mockito.when(batchResult.getResult()).thenReturn(new Result[] { r1 }).thenReturn((new Result[] { r2 })).thenReturn(new Result[] { r3 });
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    JobInfo jobInfo = Mockito.mock(JobInfo.class);
    Mockito.when(connection.createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.insert), Mockito.eq(false))).thenReturn(jobInfo);
    Mockito.when(connection.getBulkResults(Mockito.any(JobInfo.class), Mockito.anyList())).thenReturn(new BatchResult[] { batchResult, batchResult, batchResult });
    SalesForceExecutionFactory config = new SalesForceExecutionFactory();
    config.setMaxBulkInsertBatchSize(1);
    InsertExecutionImpl updateExecution = new InsertExecutionImpl(config, insert, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
    while (true) {
        try {
            updateExecution.execute();
            org.junit.Assert.assertArrayEquals(new int[] { 1, 1, -3 }, updateExecution.getUpdateCounts());
            break;
        } catch (DataNotAvailableException e) {
            continue;
        }
    }
    Mockito.verify(connection, Mockito.times(1)).createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.insert), Mockito.eq(false));
    Mockito.verify(connection, Mockito.times(1)).getBulkResults(Mockito.any(JobInfo.class), Mockito.anyList());
}
Also used : NamedTable(org.teiid.language.NamedTable) ArrayList(java.util.ArrayList) Error(com.sforce.async.Error) Insert(org.teiid.language.Insert) BatchResult(com.sforce.async.BatchResult) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Result(com.sforce.async.Result) BatchResult(com.sforce.async.BatchResult) JobInfo(com.sforce.async.JobInfo) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) ExpressionValueSource(org.teiid.language.ExpressionValueSource) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) Error(com.sforce.async.Error) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) ExecutionContext(org.teiid.translator.ExecutionContext) Expression(org.teiid.language.Expression) Parameter(org.teiid.language.Parameter) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Example 20 with ColumnReference

use of org.teiid.language.ColumnReference in project teiid by teiid.

the class TestBulkInsertExecution method testFlowAndInvocationStack.

@Test
public void testFlowAndInvocationStack() throws Exception {
    NamedTable table = new NamedTable("temp", null, Mockito.mock(Table.class));
    ArrayList<ColumnReference> elements = new ArrayList<ColumnReference>();
    elements.add(new ColumnReference(table, "one", Mockito.mock(Column.class), Integer.class));
    elements.add(new ColumnReference(table, "two", Mockito.mock(Column.class), String.class));
    List<Expression> values = new ArrayList<Expression>();
    Parameter param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    param.setValueIndex(0);
    values.add(param);
    param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.STRING);
    param.setValueIndex(1);
    values.add(param);
    ExpressionValueSource valueSource = new ExpressionValueSource(values);
    Insert insert = new Insert(table, elements, valueSource);
    insert.setParameterValues(Arrays.asList(Arrays.asList(2, '2'), Arrays.asList(2, '2'), Arrays.asList(3, '3')).iterator());
    Result r1 = Mockito.mock(Result.class);
    Result r2 = Mockito.mock(Result.class);
    Result r3 = Mockito.mock(Result.class);
    Mockito.when(r1.isSuccess()).thenReturn(true);
    Mockito.when(r1.isCreated()).thenReturn(true);
    Mockito.when(r2.isSuccess()).thenReturn(true);
    Mockito.when(r2.isCreated()).thenReturn(true);
    Mockito.when(r3.isSuccess()).thenReturn(true);
    Mockito.when(r3.isCreated()).thenReturn(true);
    BatchResult batchResult = Mockito.mock(BatchResult.class);
    Mockito.when(batchResult.getResult()).thenReturn(new Result[] { r1 }).thenReturn((new Result[] { r2 })).thenReturn(new Result[] { r3 });
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    JobInfo jobInfo = Mockito.mock(JobInfo.class);
    Mockito.when(connection.createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.insert), Mockito.eq(false))).thenReturn(jobInfo);
    Mockito.when(connection.getBulkResults(Mockito.any(JobInfo.class), Mockito.anyList())).thenReturn(new BatchResult[] { batchResult, batchResult, batchResult });
    SalesForceExecutionFactory config = new SalesForceExecutionFactory();
    config.setMaxBulkInsertBatchSize(1);
    InsertExecutionImpl updateExecution = new InsertExecutionImpl(config, insert, connection, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class));
    while (true) {
        try {
            updateExecution.execute();
            org.junit.Assert.assertArrayEquals(new int[] { 1, 1, 1 }, updateExecution.getUpdateCounts());
            break;
        } catch (DataNotAvailableException e) {
            continue;
        }
    }
    Mockito.verify(connection, Mockito.times(1)).createBulkJob(Mockito.anyString(), Mockito.eq(OperationEnum.insert), Mockito.eq(false));
    Mockito.verify(connection, Mockito.times(1)).getBulkResults(Mockito.any(JobInfo.class), Mockito.anyList());
}
Also used : NamedTable(org.teiid.language.NamedTable) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) ArrayList(java.util.ArrayList) Insert(org.teiid.language.Insert) BatchResult(com.sforce.async.BatchResult) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Result(com.sforce.async.Result) BatchResult(com.sforce.async.BatchResult) ExecutionContext(org.teiid.translator.ExecutionContext) Expression(org.teiid.language.Expression) JobInfo(com.sforce.async.JobInfo) Parameter(org.teiid.language.Parameter) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource) Test(org.junit.Test)

Aggregations

ColumnReference (org.teiid.language.ColumnReference)35 Expression (org.teiid.language.Expression)14 NamedTable (org.teiid.language.NamedTable)13 Column (org.teiid.metadata.Column)12 ArrayList (java.util.ArrayList)11 TranslatorException (org.teiid.translator.TranslatorException)11 ExpressionValueSource (org.teiid.language.ExpressionValueSource)10 Literal (org.teiid.language.Literal)10 Table (org.teiid.metadata.Table)10 DerivedColumn (org.teiid.language.DerivedColumn)8 Test (org.junit.Test)7 Select (org.teiid.language.Select)6 Insert (org.teiid.language.Insert)5 List (java.util.List)4 Iterator (java.util.Iterator)3 Function (org.teiid.language.Function)3 Parameter (org.teiid.language.Parameter)3 SetQuery (org.teiid.language.SetQuery)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3