Search in sources :

Example 6 with SelectValuesMeta

use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testFilterStep.

@Test
public void testFilterStep() throws KettleException {
    SQL sql = new SQL("SELECT * FROM table WHERE foo > 1");
    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[] { 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 7 with SelectValuesMeta

use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testGenTransAllAggsNoAliases.

@Test
public void testGenTransAllAggsNoAliases() throws KettleException {
    SQL sql = new SQL("SELECT sum(foo), avg(bar), max(baz) FROM table");
    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 SelectValuesMeta

use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testTypeHandlingWithAvg.

@Test
public void testTypeHandlingWithAvg() throws KettleException {
    SQL sql = new SQL("SELECT avg( intVal ), avg( numericVal ), avg( bigNumber)  FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("intVal"));
    rowMeta.addValueMeta(new ValueMetaNumber("numericVal"));
    rowMeta.addValueMeta(new ValueMetaBigNumber("bigNumber"));
    sql.parse(rowMeta);
    SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
    SelectValuesMeta meta = (SelectValuesMeta) getStepByName(generator.generateTransMeta(), "Set Conversion");
    assertThat(meta.getMeta().length, is(3));
    // Integer should be converted to TYPE_NUMBER
    assertThat(meta.getMeta()[0].getType(), is(TYPE_NUMBER));
    // Other types should be left alone ( SelectMetadataChange.getType remains TYPE_NONE )
    assertThat(meta.getMeta()[1].getType(), is(TYPE_NONE));
    assertThat(meta.getMeta()[2].getType(), is(TYPE_NONE));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 9 with SelectValuesMeta

use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta 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 10 with SelectValuesMeta

use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta 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)

Aggregations

SelectValuesMeta (org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta)18 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)15 Test (org.junit.Test)13 SQL (org.pentaho.di.core.sql.SQL)13 RowMeta (org.pentaho.di.core.row.RowMeta)12 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)12 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)9 StepMeta (org.pentaho.di.trans.step.StepMeta)5 KettleException (org.pentaho.di.core.exception.KettleException)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 SQLField (org.pentaho.di.core.sql.SQLField)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)2 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Condition (org.pentaho.di.core.Condition)1