Search in sources :

Example 1 with ValueMetaAndData

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

the class BeamPipelineMetaUtil method generateFilterRowsPipelineMeta.

public static final PipelineMeta generateFilterRowsPipelineMeta(String transname, String inputTransformName, String outputTransformName, IHopMetadataProvider metadataProvider) throws Exception {
    IHopMetadataSerializer<FileDefinition> serializer = metadataProvider.getSerializer(FileDefinition.class);
    FileDefinition customerFileDefinition = createCustomersInputFileDefinition();
    serializer.save(customerFileDefinition);
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.setName(transname);
    pipelineMeta.setMetadataProvider(metadataProvider);
    // Add the io transform
    // 
    BeamInputMeta beamInputMeta = new BeamInputMeta();
    beamInputMeta.setInputLocation(PipelineTestBase.INPUT_CUSTOMERS_FILE);
    beamInputMeta.setFileDefinitionName(customerFileDefinition.getName());
    TransformMeta beamInputTransformMeta = new TransformMeta(inputTransformName, beamInputMeta);
    beamInputTransformMeta.setTransformPluginId(BeamConst.STRING_BEAM_INPUT_PLUGIN_ID);
    pipelineMeta.addTransform(beamInputTransformMeta);
    // Add 2 add constants transforms A and B
    // 
    ConstantMeta constantA = new ConstantMeta();
    ConstantField cf1 = new ConstantField("label", "String", "< 'k'");
    constantA.getFields().add(cf1);
    TransformMeta constantAMeta = new TransformMeta("A", constantA);
    pipelineMeta.addTransform(constantAMeta);
    ConstantMeta constantB = new ConstantMeta();
    ConstantField cf2 = new ConstantField("label", "String", ">= 'k'");
    constantB.getFields().add(cf2);
    TransformMeta constantBMeta = new TransformMeta("B", constantB);
    pipelineMeta.addTransform(constantBMeta);
    // Add Filter rows transform looking for customers name > "k"
    // Send rows to A (true) and B (false)
    // 
    FilterRowsMeta filter = new FilterRowsMeta();
    filter.getCondition().setLeftValuename("name");
    filter.getCondition().setFunction(Condition.FUNC_SMALLER);
    filter.getCondition().setRightExact(new ValueMetaAndData("value", "k"));
    filter.setTrueTransformName("A");
    filter.setFalseTransformName("B");
    TransformMeta filterMeta = new TransformMeta("Filter", filter);
    pipelineMeta.addTransform(filterMeta);
    pipelineMeta.addPipelineHop(new PipelineHopMeta(beamInputTransformMeta, filterMeta));
    pipelineMeta.addPipelineHop(new PipelineHopMeta(filterMeta, constantAMeta));
    pipelineMeta.addPipelineHop(new PipelineHopMeta(filterMeta, constantBMeta));
    // Add a dummy behind it all to flatten/merge the data again...
    // 
    DummyMeta dummyPipelineMeta = new DummyMeta();
    TransformMeta dummyTransformMeta = new TransformMeta("Flatten", dummyPipelineMeta);
    pipelineMeta.addTransform(dummyTransformMeta);
    pipelineMeta.addPipelineHop(new PipelineHopMeta(constantAMeta, dummyTransformMeta));
    pipelineMeta.addPipelineHop(new PipelineHopMeta(constantBMeta, dummyTransformMeta));
    // Add the output transform
    // 
    BeamOutputMeta beamOutputMeta = new BeamOutputMeta();
    beamOutputMeta.setOutputLocation("/tmp/customers/output/");
    beamOutputMeta.setFileDefinitionName(null);
    beamOutputMeta.setFilePrefix("filter-test");
    beamOutputMeta.setFileSuffix(".csv");
    // Not yet supported
    beamOutputMeta.setWindowed(false);
    TransformMeta beamOutputTransformMeta = new TransformMeta(outputTransformName, beamOutputMeta);
    beamOutputTransformMeta.setTransformPluginId("BeamOutput");
    pipelineMeta.addTransform(beamOutputTransformMeta);
    pipelineMeta.addPipelineHop(new PipelineHopMeta(dummyTransformMeta, beamOutputTransformMeta));
    return pipelineMeta;
}
Also used : FilterRowsMeta(org.apache.hop.pipeline.transforms.filterrows.FilterRowsMeta) DummyMeta(org.apache.hop.pipeline.transforms.dummy.DummyMeta) FileDefinition(org.apache.hop.beam.metadata.FileDefinition) ConstantField(org.apache.hop.pipeline.transforms.constant.ConstantField) BeamOutputMeta(org.apache.hop.beam.transforms.io.BeamOutputMeta) BeamInputMeta(org.apache.hop.beam.transforms.io.BeamInputMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) ValueMetaAndData(org.apache.hop.core.row.ValueMetaAndData) ConstantMeta(org.apache.hop.pipeline.transforms.constant.ConstantMeta) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 2 with ValueMetaAndData

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

the class EnterValueDialog method test.

/**
 * Test the entered value
 */
public void test() {
    try {
        ValueMetaAndData v = getValue(valueMeta.getName());
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        StringBuilder result = new StringBuilder();
        result.append(Const.CR).append(Const.CR).append("    ").append(v.toString());
        result.append(Const.CR).append("    ").append(v.toStringMeta());
        mb.setMessage(BaseMessages.getString(PKG, "EnterValueDialog.TestResult.Message", result.toString()));
        mb.setText(BaseMessages.getString(PKG, "EnterValueDialog.TestResult.Title"));
        mb.open();
    } catch (HopValueException e) {
        new ErrorDialog(shell, "Error", "There was an error during data type conversion: ", e);
    }
}
Also used : HopValueException(org.apache.hop.core.exception.HopValueException) ValueMetaAndData(org.apache.hop.core.row.ValueMetaAndData)

Example 3 with ValueMetaAndData

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

the class ConditionTest method testNullLessThanNumberEvaluatesAsFalse.

@Test
public void testNullLessThanNumberEvaluatesAsFalse() throws Exception {
    IRowMeta rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(new ValueMetaInteger("name1"));
    String left = "name1";
    ValueMetaAndData rightExact = new ValueMetaAndData(new ValueMetaInteger("name1"), new Long(-10));
    Condition condition = new Condition(left, Condition.FUNC_SMALLER, null, rightExact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
    condition = new Condition(left, Condition.FUNC_SMALLER_EQUAL, null, rightExact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
}
Also used : IRowMeta(org.apache.hop.core.row.IRowMeta) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) ValueMetaAndData(org.apache.hop.core.row.ValueMetaAndData) Test(org.junit.Test)

Example 4 with ValueMetaAndData

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

the class EnterValueDialog method getValue.

private ValueMetaAndData getValue(String valuename) throws HopValueException {
    try {
        int valtype = ValueMetaFactory.getIdForValueMeta(wValueType.getText());
        ValueMetaAndData val = new ValueMetaAndData(valuename, wInputString.getText());
        IValueMeta valueMeta = ValueMetaFactory.cloneValueMeta(val.getValueMeta(), valtype);
        Object valueData = val.getValueData();
        int formatIndex = wFormat.getSelectionIndex();
        valueMeta.setConversionMask(formatIndex >= 0 ? wFormat.getItem(formatIndex) : wFormat.getText());
        valueMeta.setLength(Const.toInt(wLength.getText(), -1));
        valueMeta.setPrecision(Const.toInt(wPrecision.getText(), -1));
        val.setValueMeta(valueMeta);
        IValueMeta stringValueMeta = new ValueMetaString(valuename);
        stringValueMeta.setConversionMetadata(valueMeta);
        Object targetData = stringValueMeta.convertDataUsingConversionMetaData(valueData);
        val.setValueData(targetData);
        return val;
    } catch (Exception e) {
        throw new HopValueException(e);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) HopValueException(org.apache.hop.core.exception.HopValueException) ValueMetaAndData(org.apache.hop.core.row.ValueMetaAndData) HopValueException(org.apache.hop.core.exception.HopValueException)

Example 5 with ValueMetaAndData

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

the class FilterRowsMeta method readData.

private void readData(Node transformNode) throws HopXmlException {
    try {
        setTrueTransformName(XmlHandler.getTagValue(transformNode, "send_true_to"));
        setFalseTransformName(XmlHandler.getTagValue(transformNode, "send_false_to"));
        Node compare = XmlHandler.getSubNode(transformNode, "compare");
        Node condnode = XmlHandler.getSubNode(compare, "condition");
        // The new situation...
        if (condnode != null) {
            condition = new Condition(condnode);
        } else {
            // Old style condition: Line1 OR Line2 OR Line3: @deprecated!
            condition = new Condition();
            int nrkeys = XmlHandler.countNodes(compare, "key");
            if (nrkeys == 1) {
                Node knode = XmlHandler.getSubNodeByNr(compare, "key", 0);
                String key = XmlHandler.getTagValue(knode, "name");
                String value = XmlHandler.getTagValue(knode, "value");
                String field = XmlHandler.getTagValue(knode, "field");
                String comparator = XmlHandler.getTagValue(knode, "condition");
                condition.setOperator(Condition.OPERATOR_NONE);
                condition.setLeftValuename(key);
                condition.setFunction(Condition.getFunction(comparator));
                condition.setRightValuename(field);
                condition.setRightExact(new ValueMetaAndData("value", value));
            } else {
                for (int i = 0; i < nrkeys; i++) {
                    Node knode = XmlHandler.getSubNodeByNr(compare, "key", i);
                    String key = XmlHandler.getTagValue(knode, "name");
                    String value = XmlHandler.getTagValue(knode, "value");
                    String field = XmlHandler.getTagValue(knode, "field");
                    String comparator = XmlHandler.getTagValue(knode, "condition");
                    Condition subc = new Condition();
                    if (i > 0) {
                        subc.setOperator(Condition.OPERATOR_OR);
                    } else {
                        subc.setOperator(Condition.OPERATOR_NONE);
                    }
                    subc.setLeftValuename(key);
                    subc.setFunction(Condition.getFunction(comparator));
                    subc.setRightValuename(field);
                    subc.setRightExact(new ValueMetaAndData("value", value));
                    condition.addCondition(subc);
                }
            }
        }
    } catch (Exception e) {
        throw new HopXmlException(BaseMessages.getString(PKG, "FilterRowsMeta.Exception..UnableToLoadTransformMetaFromXML"), e);
    }
}
Also used : Condition(org.apache.hop.core.Condition) HopXmlException(org.apache.hop.core.exception.HopXmlException) Node(org.w3c.dom.Node) ValueMetaAndData(org.apache.hop.core.row.ValueMetaAndData) HopException(org.apache.hop.core.exception.HopException) HopXmlException(org.apache.hop.core.exception.HopXmlException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException)

Aggregations

ValueMetaAndData (org.apache.hop.core.row.ValueMetaAndData)6 HopValueException (org.apache.hop.core.exception.HopValueException)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)2 FileDefinition (org.apache.hop.beam.metadata.FileDefinition)1 BeamInputMeta (org.apache.hop.beam.transforms.io.BeamInputMeta)1 BeamOutputMeta (org.apache.hop.beam.transforms.io.BeamOutputMeta)1 Condition (org.apache.hop.core.Condition)1 HopException (org.apache.hop.core.exception.HopException)1 HopTransformException (org.apache.hop.core.exception.HopTransformException)1 HopXmlException (org.apache.hop.core.exception.HopXmlException)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 IValueMeta (org.apache.hop.core.row.IValueMeta)1 RowMeta (org.apache.hop.core.row.RowMeta)1 ValueMetaInteger (org.apache.hop.core.row.value.ValueMetaInteger)1 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)1 ConstantField (org.apache.hop.pipeline.transforms.constant.ConstantField)1 ConstantMeta (org.apache.hop.pipeline.transforms.constant.ConstantMeta)1 DummyMeta (org.apache.hop.pipeline.transforms.dummy.DummyMeta)1