Search in sources :

Example 1 with MemoryMetadataProvider

use of org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider 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 MemoryMetadataProvider

use of org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider 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 MemoryMetadataProvider

use of org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider 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 MemoryMetadataProvider

use of org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider in project hop by apache.

the class MultiMetadataProviderTest method testSetProviders.

public void testSetProviders() {
    List<IHopMetadataProvider> list = multiMetadataProvider.getProviders();
    MemoryMetadataProvider provider4 = new MemoryMetadataProvider(new HopTwoWayPasswordEncoder(), Variables.getADefaultVariableSpace());
    provider4.setDescription("Provider4");
    list.add(provider4);
    multiMetadataProvider.setProviders(list);
    assertEquals(4, multiMetadataProvider.getProviders().size());
    // see if the description has changed...
    // 
    assertEquals("Multi Metadata Provider: Provider1, Provider2, Provider3, Provider4", multiMetadataProvider.getDescription());
}
Also used : HopTwoWayPasswordEncoder(org.apache.hop.core.encryption.HopTwoWayPasswordEncoder) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider)

Example 5 with MemoryMetadataProvider

use of org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider in project hop by apache.

the class LoadSaveBase method createValidatorMapAndInvokeSetters.

@SuppressWarnings({ "unchecked" })
protected Map<String, IFieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
    Map<String, IFieldLoadSaveValidator<?>> validatorMap = new HashMap<>();
    metadataProvider = new MemoryMetadataProvider();
    for (String attribute : attributes) {
        IGetter<?> getter = manipulator.getGetter(attribute);
        @SuppressWarnings("rawtypes") ISetter setter = manipulator.getSetter(attribute);
        IFieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
        try {
            Object testValue = validator.getTestObject();
            // no-inspection unchecked
            setter.set(metaToSave, testValue);
            if (testValue instanceof DatabaseMeta) {
                addDatabase((DatabaseMeta) testValue);
            } else if (testValue instanceof DatabaseMeta[]) {
                addDatabase((DatabaseMeta[]) testValue);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to invoke setter for " + attribute, e);
        }
        validatorMap.put(attribute, validator);
    }
    return validatorMap;
}
Also used : ISetter(org.apache.hop.pipeline.transforms.loadsave.setter.ISetter) IFieldLoadSaveValidator(org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) HopException(org.apache.hop.core.exception.HopException) MemoryMetadataProvider(org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)

Aggregations

MemoryMetadataProvider (org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider)17 Before (org.junit.Before)6 Test (org.junit.Test)6 BeanInjectionInfo (org.apache.hop.core.injection.bean.BeanInjectionInfo)5 BeanInjector (org.apache.hop.core.injection.bean.BeanInjector)5 RowMetaAndData (org.apache.hop.core.RowMetaAndData)4 IRowMeta (org.apache.hop.core.row.IRowMeta)4 RowMetaBuilder (org.apache.hop.core.row.RowMetaBuilder)4 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)3 IVariables (org.apache.hop.core.variables.IVariables)3 HopTwoWayPasswordEncoder (org.apache.hop.core.encryption.HopTwoWayPasswordEncoder)2 ITwoWayPasswordEncoder (org.apache.hop.core.encryption.ITwoWayPasswordEncoder)2 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 BeamDirectPipelineEngine (org.apache.hop.beam.engines.direct.BeamDirectPipelineEngine)1 BeamFlinkPipelineEngine (org.apache.hop.beam.engines.flink.BeamFlinkPipelineEngine)1 BeamSparkPipelineEngine (org.apache.hop.beam.engines.spark.BeamSparkPipelineEngine)1 FileDefinition (org.apache.hop.beam.metadata.FileDefinition)1 BeamBQInputMeta (org.apache.hop.beam.transforms.bq.BeamBQInputMeta)1