Search in sources :

Example 6 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testGenerateConstStep.

@Test
public void testGenerateConstStep() throws KettleException {
    SQL sql = new SQL("SELECT 'FOO' as foo FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("foo"));
    sql.parse(rowMeta);
    SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
    SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta(generator.generateTransMeta());
    assertThat(selectValuesMeta.getSelectName(), equalTo(new String[] { "'FOO'" }));
    assertThat(selectValuesMeta.getSelectRename(), equalTo(new String[] { "foo" }));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 7 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testGenTransUsingSqlWithGroupByOrderByNoAlias.

@Test
public void testGenTransUsingSqlWithGroupByOrderByNoAlias() throws KettleException {
    SQL sql = new SQL("SELECT foo, bar, baz FROM table GROUP BY foo, bar, baz ORDER BY foo");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("foo"));
    rowMeta.addValueMeta(new ValueMetaInteger("bar"));
    rowMeta.addValueMeta(new ValueMetaString("baz"));
    sql.parse(rowMeta);
    SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
    SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta(generator.generateTransMeta());
    assertThat(selectValuesMeta.getSelectName(), equalTo(new String[] { "foo", "bar", "baz" }));
    assertThat(selectValuesMeta.getSelectRename(), equalTo(new String[] { null, null, null }));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 8 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testGenerateIifStep.

@Test
public void testGenerateIifStep() throws KettleException {
    SQL sql = new SQL("SELECT IIF(10 > 1, 'TRUE', 'FALSE') FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("foo"));
    sql.parse(rowMeta);
    SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
    SelectValuesMeta selectValuesMeta = getSelectStepValuesMeta(generator.generateTransMeta());
    assertThat(selectValuesMeta.getSelectName(), equalTo(new String[] { "IIF(10 > 1, 'TRUE', 'FALSE')" }));
    assertThat(selectValuesMeta.getSelectRename(), equalTo(new String[] { null }));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 9 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceTest method setUp.

@Before
public void setUp() throws Exception {
    rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("ID"));
    rowMeta.addValueMeta(new ValueMetaInteger("A"));
    rowMeta.addValueMeta(new ValueMetaInteger("B"));
    testData = Lists.newArrayListWithExpectedSize(100);
    for (long i = 0; i < 100; i++) {
        testData.add(new RowMetaAndData(rowMeta, String.valueOf(i), i % 13, i % 17));
    }
    when(serviceTrans.findRunThread(SERVICE_STEP)).thenReturn(serviceStep);
    when(serviceStep.getTrans()).thenReturn(serviceTrans);
    when(sqlTransGenerator.getInjectorStepName()).thenReturn(INJECTOR_STEP);
    transMeta = serviceTrans.getTransMeta();
    when(transMeta.getCacheVersion()).thenReturn(1);
    dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName(SERVICE_NAME);
    dataServiceMeta.setStepname(SERVICE_STEP);
    when(transMeta.getStepFields(SERVICE_STEP)).thenReturn(rowMeta);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Before(org.junit.Before)

Example 10 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-cassandra-plugin by pentaho.

the class DriverCQLRowHandlerTest method testExpandCollection.

@Test
public void testExpandCollection() throws Exception {
    List<Object[]> rowList = new ArrayList<Object[]>();
    ArrayList<Long> numList = new ArrayList<Long>();
    numList.add(1L);
    numList.add(2L);
    numList.add(3L);
    rowList.add(new Object[] { 1L, numList });
    rowList.add(new Object[] { 2L, new ArrayList<Long>() });
    Iterator<Object[]> it = rowList.iterator();
    DriverKeyspace keyspace = mock(DriverKeyspace.class);
    Session session = mock(Session.class);
    ResultSet rs = mock(ResultSet.class);
    when(session.execute(anyString())).thenReturn(rs);
    when(rs.isExhausted()).then(invoc -> {
        return !it.hasNext();
    });
    when(rs.one()).then(invocation -> {
        Object[] rowArr = it.next();
        Row row = mock(Row.class);
        when(row.getObject(anyInt())).then(invoc -> {
            return rowArr[(int) invoc.getArguments()[0]];
        });
        when(row.getLong(0)).thenReturn((long) rowArr[0]);
        return row;
    });
    mockColumnDefinitions(rs, DataType.bigint(), DataType.list(DataType.bigint()));
    DriverCQLRowHandler rowHandler = new DriverCQLRowHandler(keyspace, session, true);
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("id"));
    rowMeta.addValueMeta(new ValueMetaNumber("nums"));
    rowHandler.newRowQuery(mock(StepInterface.class), "tab", "select * from tab", null, null, mock(LogChannelInterface.class));
    List<Object[]> resultRows = getNextOutputRows(rowHandler, rowMeta);
    assertEquals(4, resultRows.size());
    assertEquals(1L, resultRows.get(0)[1]);
    assertEquals(2L, resultRows.get(3)[0]);
    assertNull(resultRows.get(3)[1]);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepInterface(org.pentaho.di.trans.step.StepInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ResultSet(com.datastax.driver.core.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Row(com.datastax.driver.core.Row) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)314 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)209 RowMeta (org.pentaho.di.core.row.RowMeta)146 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)137 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)113 Test (org.junit.Test)90 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)64 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)61 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)57 KettleException (org.pentaho.di.core.exception.KettleException)41 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ObjectId (org.pentaho.di.repository.ObjectId)33 ArrayList (java.util.ArrayList)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)21 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)20 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)18 SQLException (java.sql.SQLException)17