Search in sources :

Example 1 with ValueMetaNumber

use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.

the class ScriptValuesMetaInjectionTest method test.

@Test
public void test() throws Exception {
    /*
        check( "COMPATIBILITY_MODE", new IBooleanGetter() {
          public boolean get() {
            return meta.isCompatible();
          }
        } );
    */
    check("OPTIMIZATION_LEVEL", () -> meta.getOptimizationLevel());
    check("FIELD_NAME", () -> meta.getFieldname()[0]);
    check("FIELD_RENAME_TO", () -> meta.getRename()[0]);
    check("FIELD_REPLACE", () -> meta.getReplace()[0]);
    check("SCRIPT_NAME", () -> meta.getJSScripts()[0].getScriptName());
    check("SCRIPT", () -> meta.getJSScripts()[0].getScript());
    // field type requires special handling, since it's stored as an array of ints, but injected as
    // strings
    skipPropertyTest("FIELD_TYPE");
    IValueMeta mftt = new ValueMetaString("f");
    injector.setProperty(meta, "FIELD_TYPE", setValue(mftt, "String"), "f");
    assertEquals(IValueMeta.TYPE_STRING, meta.getType()[0]);
    // reset the types array, so we can set it again
    meta.setType(new int[] {});
    injector.setProperty(meta, "FIELD_TYPE", setValue(mftt, "Integer"), "f");
    assertEquals(IValueMeta.TYPE_INTEGER, meta.getType()[0]);
    // length and precision fields also need special handing, to ensure that we get -1 when the
    // injected string value
    // is empty or null
    skipPropertyTest("FIELD_LENGTH");
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString(""), ""), "");
    assertEquals(-1, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString(" "), " "), " ");
    assertEquals(-1, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString(null), null), null);
    assertEquals(-1, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString("5"), "5"), "5");
    assertEquals(5, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), new Long(5)), "5");
    assertEquals(5, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), (Long) null), "5");
    assertEquals(-1, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaNumber("5"), new Double(5)), "5");
    assertEquals(5, meta.getLength()[0]);
    injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), (Double) null), "5");
    assertEquals(-1, meta.getLength()[0]);
    skipPropertyTest("FIELD_PRECISION");
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString(""), ""), "");
    assertEquals(-1, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString(" "), " "), " ");
    assertEquals(-1, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString(null), null), null);
    assertEquals(-1, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString("5"), "5"), "5");
    assertEquals(5, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), new Long(5)), "5");
    assertEquals(5, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), (Long) null), "5");
    assertEquals(-1, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaNumber("5"), new Double(5)), "5");
    assertEquals(5, meta.getPrecision()[0]);
    injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), (Double) null), "5");
    assertEquals(-1, meta.getPrecision()[0]);
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaNumber(org.apache.hop.core.row.value.ValueMetaNumber) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) BaseMetadataInjectionTest(org.apache.hop.core.injection.BaseMetadataInjectionTest) Test(org.junit.Test)

Example 2 with ValueMetaNumber

use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.

the class JsonInputTest method testIndexList.

@Test
public void testIndexList() throws Exception {
    final String jsonInputField = getBasicTestJson();
    testSimpleJsonPath("$..book[1,3].price", new ValueMetaNumber("price"), new Object[][] { new Object[] { jsonInputField } }, new Object[][] { new Object[] { jsonInputField, 12.99 }, new Object[] { jsonInputField, 22.99 } });
}
Also used : ValueMetaNumber(org.apache.hop.core.row.value.ValueMetaNumber) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString)

Example 3 with ValueMetaNumber

use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.

the class JsonInputTest method testChildDot.

@Test
public void testChildDot() throws Exception {
    final String jsonInputField = getBasicTestJson();
    testSimpleJsonPath("$.store.bicycle.color", new ValueMetaString("bcol"), new Object[][] { new Object[] { jsonInputField } }, new Object[][] { new Object[] { jsonInputField, "red" } });
    testSimpleJsonPath("$.store.bicycle.price", new ValueMetaNumber("p"), new Object[][] { new Object[] { jsonInputField } }, new Object[][] { new Object[] { jsonInputField, 19.95 } });
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaNumber(org.apache.hop.core.row.value.ValueMetaNumber) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString)

Example 4 with ValueMetaNumber

use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.

the class MemoryGroupByAggregationTest method testDefault.

@Test
@Ignore
public void testDefault() throws Exception {
    addColumn(new ValueMetaInteger("intg"), 0L, 1L, 1L, 10L);
    addColumn(new ValueMetaInteger("nul"));
    addColumn(new ValueMetaInteger("mix1"), -1L, 2L);
    addColumn(new ValueMetaInteger("mix2"), null, 7L);
    addColumn(new ValueMetaNumber("mix3"), -1.0, 2.5);
    addColumn(new ValueMetaDate("date1"), new Date(1L), new Date(2L));
    RowMetaAndData output = runTransform();
    assertThat(output.getInteger("intg_min"), is(0L));
    assertThat(output.getInteger("intg_max"), is(10L));
    assertThat(output.getInteger("intg_sum"), is(12L));
    assertThat(output.getInteger("intg_ave"), is(3L));
    assertThat(output.getInteger("intg_count"), is(4L));
    assertThat(output.getInteger("intg_count_any"), is(4L));
    assertThat(output.getInteger("intg_count_distinct"), is(3L));
    assertThat(output.getInteger("nul_min"), nullValue());
    assertThat(output.getInteger("nul_max"), nullValue());
    assertThat(output.getInteger("nul_sum"), nullValue());
    assertThat(output.getInteger("nul_ave"), nullValue());
    assertThat(output.getInteger("nul_count"), is(0L));
    assertThat(output.getInteger("nul_count_any"), is(4L));
    assertThat(output.getInteger("nul_count_distinct"), is(0L));
    assertThat(output.getInteger("mix1_max"), is(2L));
    assertThat(output.getInteger("mix1_min"), is(-1L));
    assertThat(output.getInteger("mix1_sum"), is(1L));
    assertThat(output.getInteger("mix1_ave"), is(0L));
    assertThat(output.getInteger("mix1_count"), is(2L));
    assertThat(output.getInteger("mix1_count_any"), is(4L));
    assertThat(output.getInteger("mix1_count_distinct"), is(2L));
    assertThat(output.getInteger("mix2_max"), is(7L));
    assertThat(output.getInteger("mix2_min"), is(7L));
    assertThat(output.getInteger("mix2_sum"), is(7L));
    assertThat(output.getNumber("mix2_ave", Double.NaN), is(7.0));
    assertThat(output.getInteger("mix2_count"), is(1L));
    assertThat(output.getInteger("mix2_count_any"), is(4L));
    assertThat(output.getInteger("mix2_count_distinct"), is(1L));
    assertThat(output.getNumber("mix3_max", Double.NaN), is(2.5));
    assertThat(output.getNumber("mix3_min", Double.NaN), is(-1.0));
    assertThat(output.getNumber("mix3_sum", Double.NaN), is(1.5));
    assertThat(output.getNumber("mix3_ave", Double.NaN), is(0.75));
    assertThat(output.getInteger("mix3_count"), is(2L));
    assertThat(output.getInteger("mix3_count_any"), is(4L));
    assertThat(output.getInteger("mix3_count_distinct"), is(2L));
    assertThat(output.getNumber("date1_min", Double.NaN), is(1.0));
    assertThat(output.getNumber("date1_max", Double.NaN), is(2.0));
    assertThat(output.getNumber("date1_sum", Double.NaN), is(3.0));
    assertThat(output.getNumber("date1_ave", Double.NaN), is(1.5));
    assertThat(output.getInteger("date1_count"), is(2L));
    assertThat(output.getInteger("date1_count_any"), is(4L));
    assertThat(output.getInteger("date1_count_distinct"), is(2L));
}
Also used : RowMetaAndData(org.apache.hop.core.RowMetaAndData) ValueMetaNumber(org.apache.hop.core.row.value.ValueMetaNumber) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate)

Example 5 with ValueMetaNumber

use of org.apache.hop.core.row.value.ValueMetaNumber in project hop by apache.

the class MemoryGroupBy method newAggregate.

/**
 * Used for junits in MemoryGroupByNewAggregateTest
 *
 * @param r
 * @param aggregate
 * @throws HopException
 */
void newAggregate(Object[] r, Aggregate aggregate) throws HopException {
    if (aggregate == null) {
        data.aggMeta = new RowMeta();
    } else {
        aggregate.counts = new long[data.subjectnrs.length];
        // Put all the counters at 0
        for (int i = 0; i < aggregate.counts.length; i++) {
            aggregate.counts[i] = 0;
        }
        aggregate.distinctObjs = null;
        aggregate.agg = new Object[data.subjectnrs.length];
        // sets all doubles to 0.0
        aggregate.mean = new double[data.subjectnrs.length];
    }
    for (int i = 0; i < data.subjectnrs.length; i++) {
        IValueMeta subjMeta = data.inputRowMeta.getValueMeta(data.subjectnrs[i]);
        Object v = null;
        IValueMeta vMeta = null;
        switch(meta.getAggregateType()[i]) {
            case MemoryGroupByMeta.TYPE_GROUP_MEDIAN:
            case MemoryGroupByMeta.TYPE_GROUP_PERCENTILE:
                vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
                v = new ArrayList<Double>();
                break;
            case MemoryGroupByMeta.TYPE_GROUP_STANDARD_DEVIATION:
                vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
                break;
            case MemoryGroupByMeta.TYPE_GROUP_COUNT_DISTINCT:
            case MemoryGroupByMeta.TYPE_GROUP_COUNT_ANY:
            case MemoryGroupByMeta.TYPE_GROUP_COUNT_ALL:
                vMeta = new ValueMetaInteger(meta.getAggregateField()[i]);
                break;
            case MemoryGroupByMeta.TYPE_GROUP_SUM:
            case MemoryGroupByMeta.TYPE_GROUP_AVERAGE:
                vMeta = !compatibilityMode && subjMeta.isNumeric() ? subjMeta.clone() : new ValueMetaNumber();
                vMeta.setName(meta.getAggregateField()[i]);
                break;
            case MemoryGroupByMeta.TYPE_GROUP_FIRST:
            case MemoryGroupByMeta.TYPE_GROUP_LAST:
            case MemoryGroupByMeta.TYPE_GROUP_FIRST_INCL_NULL:
            case MemoryGroupByMeta.TYPE_GROUP_LAST_INCL_NULL:
            case MemoryGroupByMeta.TYPE_GROUP_MIN:
            case MemoryGroupByMeta.TYPE_GROUP_MAX:
                vMeta = subjMeta.clone();
                vMeta.setName(meta.getAggregateField()[i]);
                v = r == null ? null : r[data.subjectnrs[i]];
                break;
            case MemoryGroupByMeta.TYPE_GROUP_CONCAT_COMMA:
                vMeta = new ValueMetaString(meta.getAggregateField()[i]);
                v = new StringBuilder();
                break;
            case MemoryGroupByMeta.TYPE_GROUP_CONCAT_STRING:
                vMeta = new ValueMetaString(meta.getAggregateField()[i]);
                v = new StringBuilder();
                break;
            default:
                throw new HopException("Unknown data type for aggregation : " + meta.getAggregateField()[i]);
        }
        if (meta.getAggregateType()[i] != MemoryGroupByMeta.TYPE_GROUP_COUNT_ALL && meta.getAggregateType()[i] != MemoryGroupByMeta.TYPE_GROUP_COUNT_DISTINCT && meta.getAggregateType()[i] != MemoryGroupByMeta.TYPE_GROUP_COUNT_ANY) {
            vMeta.setLength(subjMeta.getLength(), subjMeta.getPrecision());
        }
        if (aggregate == null) {
            data.aggMeta.addValueMeta(vMeta);
        } else {
            aggregate.agg[i] = v;
        }
    }
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaNumber(org.apache.hop.core.row.value.ValueMetaNumber) HopException(org.apache.hop.core.exception.HopException) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger)

Aggregations

ValueMetaNumber (org.apache.hop.core.row.value.ValueMetaNumber)27 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)18 ValueMetaInteger (org.apache.hop.core.row.value.ValueMetaInteger)11 ValueMetaBinary (org.apache.hop.core.row.value.ValueMetaBinary)7 IRowMeta (org.apache.hop.core.row.IRowMeta)5 IValueMeta (org.apache.hop.core.row.IValueMeta)5 HopException (org.apache.hop.core.exception.HopException)4 RowMeta (org.apache.hop.core.row.RowMeta)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 RowMetaAndData (org.apache.hop.core.RowMetaAndData)3 ValueMetaDate (org.apache.hop.core.row.value.ValueMetaDate)3 ILogChannel (org.apache.hop.core.logging.ILogChannel)2 DriverCqlRowHandler (org.apache.hop.databases.cassandra.datastax.DriverCqlRowHandler)2 DriverKeyspace (org.apache.hop.databases.cassandra.datastax.DriverKeyspace)2 ITransform (org.apache.hop.pipeline.transform.ITransform)2 Column (com.epam.parso.Column)1 ColumnFormat (com.epam.parso.ColumnFormat)1 SasFileProperties (com.epam.parso.SasFileProperties)1