Search in sources :

Example 1 with RowMetaBuilder

use of org.apache.hop.core.row.RowMetaBuilder in project hop by apache.

the class CoalesceMetaTest method testInjection.

@Test
public void testInjection() throws Exception {
    BeanInjectionInfo<CoalesceMeta> injectionInfo = new BeanInjectionInfo<>(CoalesceMeta.class);
    BeanInjector<CoalesceMeta> injector = new BeanInjector<>(injectionInfo, new MemoryMetadataProvider());
    IRowMeta resultMeta = new RowMetaBuilder().addString("name").addString("type").addString("remove?").addString("inputs").build();
    List<RowMetaAndData> resultRows = Arrays.asList(new RowMetaAndData(resultMeta, "result1", "String", "false", "A,B,C"), new RowMetaAndData(resultMeta, "result2", "String", "true", "D,E,F"), new RowMetaAndData(resultMeta, "result3", "String", "false", "G,H"));
    CoalesceMeta meta = new CoalesceMeta();
    injector.setProperty(meta, "NAME", resultRows, "name");
    injector.setProperty(meta, "TYPE", resultRows, "type");
    injector.setProperty(meta, "INPUT_FIELDS", resultRows, "inputs");
    injector.setProperty(meta, "REMOVE_INPUT_FIELDS", resultRows, "remove?");
    assertEquals(3, meta.getFields().size());
    assertEquals("result1", meta.getFields().get(0).getName());
}
Also used : BeanInjector(org.apache.hop.core.injection.bean.BeanInjector) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IRowMeta(org.apache.hop.core.row.IRowMeta) BeanInjectionInfo(org.apache.hop.core.injection.bean.BeanInjectionInfo) RowMetaBuilder(org.apache.hop.core.row.RowMetaBuilder) Test(org.junit.Test)

Example 2 with RowMetaBuilder

use of org.apache.hop.core.row.RowMetaBuilder in project hop by apache.

the class MergeJoinMetaInjectionTransform method testInjection.

@Test
public void testInjection() throws Exception {
    BeanInjectionInfo<MergeJoinMeta> injectionInfo = new BeanInjectionInfo<>(MergeJoinMeta.class);
    BeanInjector<MergeJoinMeta> injector = new BeanInjector<>(injectionInfo, new MemoryMetadataProvider());
    MergeJoinMeta meta = new MergeJoinMeta();
    IRowMeta metaRow = new RowMetaBuilder().addString("Left").addString("Right").addString("Type").build();
    List<RowMetaAndData> metaRows = Arrays.asList(new RowMetaAndData(metaRow, "left", "right", "INNER"));
    injector.setProperty(meta, "LEFT_TRANSFORM", metaRows, "Left");
    assertEquals("left", meta.getLeftTransformName());
    injector.setProperty(meta, "RIGHT_TRANSFORM", metaRows, "Right");
    assertEquals("right", meta.getRightTransformName());
    injector.setProperty(meta, "JOIN_TYPE", metaRows, "Type");
    assertEquals("INNER", meta.getJoinType());
    IRowMeta keyMeta = new RowMetaBuilder().addString("id").build();
    List<RowMetaAndData> key1Rows = Arrays.asList(new RowMetaAndData(keyMeta, "id11"), new RowMetaAndData(keyMeta, "id12"));
    List<RowMetaAndData> key2Rows = Arrays.asList(new RowMetaAndData(keyMeta, "id21"), new RowMetaAndData(keyMeta, "id22"), new RowMetaAndData(keyMeta, "id23"));
    injector.setProperty(meta, "KEY_FIELD1", key1Rows, "id");
    injector.setProperty(meta, "KEY_FIELD2", key2Rows, "id");
    assertEquals(2, meta.getKeyFields1().size());
    assertEquals("id11", meta.getKeyFields1().get(0));
    assertEquals("id12", meta.getKeyFields1().get(1));
    assertEquals(3, meta.getKeyFields2().size());
    assertEquals("id21", meta.getKeyFields2().get(0));
    assertEquals("id22", meta.getKeyFields2().get(1));
    assertEquals("id23", meta.getKeyFields2().get(2));
}
Also used : BeanInjector(org.apache.hop.core.injection.bean.BeanInjector) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IRowMeta(org.apache.hop.core.row.IRowMeta) BeanInjectionInfo(org.apache.hop.core.injection.bean.BeanInjectionInfo) RowMetaBuilder(org.apache.hop.core.row.RowMetaBuilder) Test(org.junit.Test)

Example 3 with RowMetaBuilder

use of org.apache.hop.core.row.RowMetaBuilder in project hop by apache.

the class AnalyticQueryMetaTest method testInjection.

@Test
public void testInjection() throws Exception {
    BeanInjectionInfo<AnalyticQueryMeta> info = new BeanInjectionInfo<>(AnalyticQueryMeta.class);
    BeanInjector<AnalyticQueryMeta> injector = new BeanInjector<>(info, new MemoryMetadataProvider());
    AnalyticQueryMeta meta = new AnalyticQueryMeta();
    IRowMeta groupMeta = new RowMetaBuilder().addString("group").build();
    List<RowMetaAndData> groupRows = Arrays.asList(new RowMetaAndData(groupMeta, "group1"), new RowMetaAndData(groupMeta, "group2"));
    injector.setProperty(meta, "GROUP_FIELDS", groupRows, "group");
    assertEquals(2, meta.getGroupFields().size());
    assertEquals("group1", meta.getGroupFields().get(0).getFieldName());
    assertEquals("group2", meta.getGroupFields().get(1).getFieldName());
    IRowMeta queryMeta = new RowMetaBuilder().addString("fieldName").addString("subject").addString("type").addString("offset").build();
    List<RowMetaAndData> queryRows = Arrays.asList(new RowMetaAndData(queryMeta, "leadResult1", "A", "LEAD", 1), new RowMetaAndData(queryMeta, "leadResult2", "A", "LEAD", 2), new RowMetaAndData(queryMeta, "lagResult1", "B", "LAG", 1), new RowMetaAndData(queryMeta, "lagResult2", "B", "LAG", 2));
    injector.setProperty(meta, "OUTPUT.AGGREGATE_FIELD", queryRows, "fieldName");
    injector.setProperty(meta, "OUTPUT.SUBJECT_FIELD", queryRows, "subject");
    injector.setProperty(meta, "OUTPUT.AGGREGATE_TYPE", queryRows, "type");
    injector.setProperty(meta, "OUTPUT.VALUE_FIELD", queryRows, "offset");
    assertEquals(4, meta.getQueryFields().size());
    int index = 0;
    assertEquals("leadResult1", meta.getQueryFields().get(index).getAggregateField());
    assertEquals("LEAD", meta.getQueryFields().get(index).getAggregateType().name());
    assertEquals("A", meta.getQueryFields().get(index).getSubjectField());
    assertEquals(1, meta.getQueryFields().get(index).getValueField());
    index++;
    assertEquals("leadResult2", meta.getQueryFields().get(index).getAggregateField());
    assertEquals("LEAD", meta.getQueryFields().get(index).getAggregateType().name());
    assertEquals("A", meta.getQueryFields().get(index).getSubjectField());
    assertEquals(2, meta.getQueryFields().get(index).getValueField());
    index++;
    assertEquals("lagResult1", meta.getQueryFields().get(index).getAggregateField());
    assertEquals("LAG", meta.getQueryFields().get(index).getAggregateType().name());
    assertEquals("B", meta.getQueryFields().get(index).getSubjectField());
    assertEquals(1, meta.getQueryFields().get(index).getValueField());
    index++;
    assertEquals("lagResult2", meta.getQueryFields().get(index).getAggregateField());
    assertEquals("LAG", meta.getQueryFields().get(index).getAggregateType().name());
    assertEquals("B", meta.getQueryFields().get(index).getSubjectField());
    assertEquals(2, meta.getQueryFields().get(index).getValueField());
}
Also used : BeanInjector(org.apache.hop.core.injection.bean.BeanInjector) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IRowMeta(org.apache.hop.core.row.IRowMeta) BeanInjectionInfo(org.apache.hop.core.injection.bean.BeanInjectionInfo) RowMetaBuilder(org.apache.hop.core.row.RowMetaBuilder) Test(org.junit.Test)

Example 4 with RowMetaBuilder

use of org.apache.hop.core.row.RowMetaBuilder in project hop by apache.

the class MetaPropInjectionTest method testHopMetadataPropertyInjection.

@Test
public void testHopMetadataPropertyInjection() throws Exception {
    // The object to inject into
    // 
    PropBeanParent parent = new PropBeanParent();
    BeanInjectionInfo<PropBeanParent> info = new BeanInjectionInfo<>(PropBeanParent.class);
    // The metadata to inject...
    // 
    RowMetaAndData parentMetadata = new RowMetaAndData();
    parentMetadata.addValue(new ValueMetaString("stringValue"), "someString");
    parentMetadata.addValue(new ValueMetaString("intValue"), "123");
    parentMetadata.addValue(new ValueMetaString("longValue"), "987654321");
    parentMetadata.addValue(new ValueMetaString("booleanValue"), "true");
    parentMetadata.addValue(new ValueMetaString("childValue1"), "cv1");
    parentMetadata.addValue(new ValueMetaString("childValue2"), "cv2");
    parentMetadata.addValue(new ValueMetaString("grandChildName"), "someName");
    parentMetadata.addValue(new ValueMetaString("grandChildDescription"), "someDescription");
    BeanInjector<PropBeanParent> injector = new BeanInjector<>(info, new MemoryMetadataProvider());
    injector.setProperty(parent, "str", Arrays.asList(parentMetadata), "stringValue");
    injector.setProperty(parent, "int", Arrays.asList(parentMetadata), "intValue");
    injector.setProperty(parent, "long", Arrays.asList(parentMetadata), "longValue");
    injector.setProperty(parent, "boolean", Arrays.asList(parentMetadata), "booleanValue");
    injector.setProperty(parent, "child1", Arrays.asList(parentMetadata), "childValue1");
    injector.setProperty(parent, "child2", Arrays.asList(parentMetadata), "childValue2");
    injector.setProperty(parent, "grand_child_name", Arrays.asList(parentMetadata), "grandChildName");
    injector.setProperty(parent, "grand_child_description", Arrays.asList(parentMetadata), "grandChildDescription");
    assertEquals(parent.getStringField(), "someString");
    assertEquals(parent.getIntField(), 123);
    assertEquals(parent.getLongField(), 987654321L);
    assertTrue(parent.isBooleanField());
    assertEquals(parent.getChild().getChildField1(), "cv1");
    assertEquals(parent.getChild().getChildField2(), "cv2");
    assertEquals("someName", parent.getChild().getGrandChild().getGrandChildName());
    assertEquals("someDescription", parent.getChild().getGrandChild().getGrandChildDescription());
    IRowMeta stringRowMeta = new RowMetaBuilder().addString("stringField").build();
    List<RowMetaAndData> stringsRows = Arrays.asList(new RowMetaAndData(stringRowMeta, "string1"), new RowMetaAndData(stringRowMeta, "string2"), new RowMetaAndData(stringRowMeta, "string3"));
    injector.setProperty(parent, "string", stringsRows, "stringField");
    assertEquals(3, parent.getStrings().size());
    assertEquals("string1", parent.getStrings().get(0));
    assertEquals("string2", parent.getStrings().get(1));
    assertEquals("string3", parent.getStrings().get(2));
    // Inject a number of children into a list
    // 
    IRowMeta entriesRowMeta = new RowMetaBuilder().addString("fieldF1").addString("fieldF2").build();
    List<RowMetaAndData> entriesRows = Arrays.asList(new RowMetaAndData(entriesRowMeta, "f1_1", "f2_1"), new RowMetaAndData(entriesRowMeta, "f1_2", "f2_2"), new RowMetaAndData(entriesRowMeta, "f1_3", "f2_3"));
    injector.setProperty(parent, "f1", entriesRows, "fieldF1");
    injector.setProperty(parent, "f2", entriesRows, "fieldF2");
    assertEquals(3, parent.getChildren().size());
    assertEquals(new PropBeanListChild("f1_1", "f2_1"), parent.getChildren().get(0));
    assertEquals(new PropBeanListChild("f1_2", "f2_2"), parent.getChildren().get(1));
    assertEquals(new PropBeanListChild("f1_3", "f2_3"), parent.getChildren().get(2));
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) BeanInjector(org.apache.hop.core.injection.bean.BeanInjector) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) RowMetaAndData(org.apache.hop.core.RowMetaAndData) PropBeanParent(org.apache.hop.core.injection.metadata.PropBeanParent) IRowMeta(org.apache.hop.core.row.IRowMeta) BeanInjectionInfo(org.apache.hop.core.injection.bean.BeanInjectionInfo) RowMetaBuilder(org.apache.hop.core.row.RowMetaBuilder) PropBeanListChild(org.apache.hop.core.injection.metadata.PropBeanListChild) Test(org.junit.Test)

Example 5 with RowMetaBuilder

use of org.apache.hop.core.row.RowMetaBuilder in project hop by apache.

the class MetadataInputMeta method getFields.

@Override
public void getFields(IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) {
    // The output fields (all type String) to consider...
    // 
    List<String> fieldNames = Arrays.asList(providerFieldName, typeKeyFieldName, typeNameFieldName, typeDescriptionFieldName, typeClassFieldName, nameFieldName, jsonFieldName);
    RowMetaBuilder builder = new RowMetaBuilder();
    for (String fieldName : fieldNames) {
        if (StringUtils.isNotEmpty(fieldName)) {
            builder.addString(fieldName);
        }
    }
    inputRowMeta.addRowMeta(builder.build());
}
Also used : RowMetaBuilder(org.apache.hop.core.row.RowMetaBuilder)

Aggregations

RowMetaBuilder (org.apache.hop.core.row.RowMetaBuilder)8 IRowMeta (org.apache.hop.core.row.IRowMeta)7 Test (org.junit.Test)6 RowMetaAndData (org.apache.hop.core.RowMetaAndData)5 BeanInjectionInfo (org.apache.hop.core.injection.bean.BeanInjectionInfo)5 BeanInjector (org.apache.hop.core.injection.bean.BeanInjector)5 MemoryMetadataProvider (org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)4 List (java.util.List)1 Schema (org.apache.avro.Schema)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 AvroFileInputMeta (org.apache.hop.avro.transforms.avroinput.AvroFileInputMeta)1 HopTransformException (org.apache.hop.core.exception.HopTransformException)1 PropBeanListChild (org.apache.hop.core.injection.metadata.PropBeanListChild)1 PropBeanParent (org.apache.hop.core.injection.metadata.PropBeanParent)1 IValueMeta (org.apache.hop.core.row.IValueMeta)1 RowMeta (org.apache.hop.core.row.RowMeta)1 ValueMetaAvroRecord (org.apache.hop.core.row.value.ValueMetaAvroRecord)1 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)1 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1