Search in sources :

Example 96 with Schema

use of io.cdap.cdap.api.data.schema.Schema in project hydrator-plugins by cdapio.

the class CountIfTest method testCondition.

@Test
public void testCondition() {
    String condition = "x > 1";
    Schema schema = Schema.recordOf("test", Schema.Field.of("x", Schema.nullableOf(Schema.of(Schema.Type.INT))));
    test(new CountIf("x", JexlCondition.of(condition)), schema, "x", 2L, Arrays.asList(1, 2, null, null, 3), new CountIf("x", JexlCondition.of(condition)));
    test(new CountIf("y", JexlCondition.of(condition)), schema, "x", 0L, Arrays.asList(1, 2, null, null, 3), new CountIf("y", JexlCondition.of(condition)));
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 97 with Schema

use of io.cdap.cdap.api.data.schema.Schema in project hydrator-plugins by cdapio.

the class CountTest method testCount.

@Test
public void testCount() {
    Schema schema = Schema.recordOf("test", Schema.Field.of("x", Schema.nullableOf(Schema.of(Schema.Type.INT))));
    test(new Count("x"), schema, "x", 3L, Arrays.asList(1, 2, null, null, 3), new Count("x"));
    test(new Count("y"), schema, "x", 0L, Arrays.asList(1, 2, null, null, 3), new Count("y"));
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 98 with Schema

use of io.cdap.cdap.api.data.schema.Schema in project hydrator-plugins by cdapio.

the class RowDenormalizerConfigTest method testDenormalizerWithWrongKeyField.

@Test(expected = ValidationException.class)
public void testDenormalizerWithWrongKeyField() throws Exception {
    Schema inputSchema = Schema.recordOf("record", Schema.Field.of("KeyField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("NameField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("ValueField", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
    MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema, Collections.emptyMap());
    RowDenormalizerConfig config = new RowDenormalizerConfig("WrongKeyField", "NameField", "ValueField", "Firstname," + "Lastname,Address", "Lastname:lname,Address:addr");
    RowDenormalizerAggregator aggregator = new RowDenormalizerAggregator(config);
    aggregator.configurePipeline(configurer);
    configurer.getStageConfigurer().getFailureCollector().getOrThrowException();
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 99 with Schema

use of io.cdap.cdap.api.data.schema.Schema in project hydrator-plugins by cdapio.

the class AvgIfTest method testFloatCondition.

@Test
public void testFloatCondition() {
    String condition = "x>-100f";
    Schema schema = Schema.recordOf("test", Schema.Field.of("x", Schema.of(Schema.Type.FLOAT)));
    Avg avg = new AvgIf("x", Schema.of(Schema.Type.FLOAT), JexlCondition.of(condition));
    Avg avg1 = new AvgIf("x", Schema.of(Schema.Type.FLOAT), JexlCondition.of(condition));
    testFunction(avg, schema, avg1, 0d, 0);
    testFunction(avg, schema, avg1, 21d / 6d, 1f, 2f, 3f, 4f, 5f, 6f, -101F);
    testFunction(avg, schema, avg1, 93d / 4d, -10f, 0f, 3f, 100f, -101F);
    testFunction(avg, schema, avg1, 0.111d / 4d, 0f, 0.1f, 0.01f, 0.001f, -101F);
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 100 with Schema

use of io.cdap.cdap.api.data.schema.Schema in project hydrator-plugins by cdapio.

the class AvgIfTest method testIntCondition.

@Test
public void testIntCondition() {
    String condition = "x>1";
    Schema schema = Schema.recordOf("test", Schema.Field.of("x", Schema.of(Schema.Type.INT)));
    AvgIf avg = new AvgIf("x", Schema.of(Schema.Type.INT), JexlCondition.of(condition));
    AvgIf avg1 = new AvgIf("x", Schema.of(Schema.Type.INT), JexlCondition.of(condition));
    testFunction(avg, schema, avg1, null, 0);
    testFunction(avg, schema, avg1, 20d / 5d, 1, 2, 3, 4, 5, 6);
    testFunction(avg, schema, avg1, 103d / 2d, -10, 0, 3, 100);
}
Also used : Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Aggregations

Schema (io.cdap.cdap.api.data.schema.Schema)1135 Test (org.junit.Test)664 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)432 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)177 Table (io.cdap.cdap.api.dataset.table.Table)169 ApplicationManager (io.cdap.cdap.test.ApplicationManager)148 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)141 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)133 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)130 ArrayList (java.util.ArrayList)114 HashSet (java.util.HashSet)113 HashMap (java.util.HashMap)101 WorkflowManager (io.cdap.cdap.test.WorkflowManager)96 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)81 IOException (java.io.IOException)69 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)67 MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)56 Map (java.util.Map)56 ETLPlugin (io.cdap.cdap.etl.proto.v2.ETLPlugin)47 ReflectionSchemaGenerator (io.cdap.cdap.internal.io.ReflectionSchemaGenerator)46