コード例 #1
0
ファイル: InjectorTest.java プロジェクト: hoverzheng/kettle
  /** Test case for injector step... also a show case on how to use injector. */
  public void testInjector() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("injectortest");

    PluginRegistry registry = PluginRegistry.getInstance();

    //
    // create an injector step...
    //
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();

    // Set the information of the injector.

    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, (StepMetaInterface) im);
    transMeta.addStep(injectorStep);

    //
    // Create a dummy step
    //
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();

    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, (StepMetaInterface) dm);
    transMeta.addStep(dummyStep);

    TransHopMeta hi = new TransHopMeta(injectorStep, dummyStep);
    transMeta.addTransHop(hi);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);

    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();

    // add rows
    List<RowMetaAndData> inputList = createData();
    for (RowMetaAndData rm : inputList) {
      rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();

    trans.waitUntilFinished();

    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, inputList);
  }
コード例 #2
0
ファイル: ConstantTest.java プロジェクト: hoverzheng/kettle
  /** Test case for Constant step. Row generator attached to a constant step. */
  public void testConstant1() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("constanttest1");

    PluginRegistry registry = PluginRegistry.getInstance();

    //
    // create a row generator step...
    //
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();

    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep =
        new StepMeta(rowGeneratorPid, rowGeneratorStepname, (StepMetaInterface) rm);
    transMeta.addStep(rowGeneratorStep);

    //
    // Generate 1 empty row
    //
    String fieldName[] = {};
    String type[] = {};
    String value[] = {};
    String fieldFormat[] = {};
    String group[] = {};
    String decimal[] = {};
    int intDummies[] = {};

    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);

    //
    // Add constant step.
    //
    String constStepname1 = "constant 1";
    ConstantMeta cnst1 = new ConstantMeta();

    String fieldName1[] = {
      "boolean1",
      "boolean2",
      "boolean3",
      "boolean4",
      "boolean5",
      "boolean6",
      "boolean7",
      "string1",
      "string2",
      "string3",
      "integer1",
      "integer2",
      "integer3",
      "integer4",
      "number1",
      "number2",
      "number3",
      "number4",
    };
    String type1[] = {
      "boolean", "Boolean", "bOOLEAN", "BOOLEAN", "boolean", "boolean", "boolean", "string",
      "string", "String", "integer", "integer", "integer", "integer", "number", "number", "number",
      "number"
    };
    String value1[] = {
      "Y",
      "T",
      "a",
      "TRUE",
      "0",
      "9",
      "",
      "AAAAAAAAAAAAAA",
      "   ",
      "",
      "-100",
      "0",
      "212",
      "",
      "-100.2",
      "0.0",
      "212.23",
      ""
    };
    String fieldFormat1[] = {
      "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
    };
    String group1[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", ",", ",", ",", ","};
    String decimal1[] = {
      "", "", "", "", "", "", "", "", "", "", "", "", "", "", ".", ".", ".", "."
    };
    String currency[] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
    int intDummies1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    cnst1.setFieldName(fieldName1);
    cnst1.setFieldType(type1);
    cnst1.setValue(value1);
    cnst1.setFieldLength(intDummies1);
    cnst1.setFieldPrecision(intDummies1);
    cnst1.setFieldFormat(fieldFormat1);
    cnst1.setGroup(group1);
    cnst1.setDecimal(decimal1);
    cnst1.setCurrency(currency);

    String addSeqPid1 = registry.getPluginId(StepPluginType.class, cnst1);
    StepMeta addSeqStep1 = new StepMeta(addSeqPid1, constStepname1, (StepMetaInterface) cnst1);
    transMeta.addStep(addSeqStep1);

    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, addSeqStep1);
    transMeta.addTransHop(hi1);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(constStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);

    trans.startThreads();

    trans.waitUntilFinished();

    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
  }
コード例 #3
0
  public void testCalculator1() throws Exception {
    KettleEnvironment.init();

    PluginRegistry registry = PluginRegistry.getInstance();
    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("calculatortest1");

    //
    // create a row generator step...
    //
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();

    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);

    //
    // Generate 1 empty row
    //
    String[] strDummies = {};
    int[] intDummies = {};

    rm.setDefault();
    rm.setFieldName(strDummies);
    rm.setFieldType(strDummies);
    rm.setValue(strDummies);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(strDummies);
    rm.setGroup(strDummies);
    rm.setDecimal(strDummies);

    //
    // Add calculator step.
    //
    String calculatorStepname1 = "calculator 1";
    CalculatorMeta calc1 = new CalculatorMeta();

    CalculatorMetaFunction[] calculations =
        new CalculatorMetaFunction[] {
          new CalculatorMetaFunction(
              "timestamp1", // fieldName
              CalculatorMetaFunction.CALC_CONSTANT, // calctype
              "1970-01-01 00:00:00.100100", // fieldA
              "", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_TIMESTAMP, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              ),
          new CalculatorMetaFunction(
              "int1", // fieldName
              CalculatorMetaFunction.CALC_CONSTANT, // calctype
              "1", // fieldA
              "", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_INTEGER, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              ),
          new CalculatorMetaFunction(
              "timestamp plus 1 day", // fieldName
              CalculatorMetaFunction.CALC_ADD_DAYS, // calctype
              "timestamp1", // fieldA
              "int1", // String fieldB
              "", // String fieldC
              ValueMetaInterface.TYPE_DATE, // valueType,
              0, // int valueLength,
              0, // int valuePrecision,
              false, // boolean removedFromResult,
              "", // String conversionMask,
              "", // String decimalSymbol,
              "", // String groupingSymbol,
              "" // String currencySymbol
              )
        };
    calc1.setCalculation(calculations);
    //
    String calculatorPid1 = registry.getPluginId(StepPluginType.class, calc1);
    StepMeta calcualtorStep1 = new StepMeta(calculatorPid1, calculatorStepname1, calc1);
    transMeta.addStep(calcualtorStep1);

    //
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, calcualtorStep1);
    transMeta.addTransHop(hi1);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(calculatorStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);

    trans.startThreads();
    trans.waitUntilFinished();

    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
  }
コード例 #4
0
  /** Test case for janino step. */
  public void testJaninoStep() throws Exception {
    KettleEnvironment.init();

    //
    // Create a new transformation...
    //
    TransMeta transMeta = new TransMeta();
    transMeta.setName("janino test");

    PluginRegistry registry = PluginRegistry.getInstance();

    // create an injector step...
    String injectorStepName = "injector step";
    InjectorMeta im = new InjectorMeta();

    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepName, im);
    transMeta.addStep(injectorStep);

    //
    // create a janino step...
    //
    String stepname = "janino";
    JaninoMeta jm = new JaninoMeta();

    // Set the information of the step
    String janinoPid = registry.getPluginId(StepPluginType.class, jm);
    StepMeta janinoStep = new StepMeta(janinoPid, stepname, jm);
    transMeta.addStep(janinoStep);

    jm.setDefault();

    JaninoMetaFunction[] formulas = {
      new JaninoMetaFunction(
          "string",
          "(string==null)?null:\"string-value\"",
          ValueMeta.TYPE_STRING,
          -1,
          -1,
          "string"),
      new JaninoMetaFunction(
          "integer",
          "(integer==null)?null:new Long(42L)",
          ValueMeta.TYPE_INTEGER,
          -1,
          -1,
          "integer"),
      new JaninoMetaFunction(
          "number",
          "(number==null)?null:new Double(23.0)",
          ValueMeta.TYPE_NUMBER,
          -1,
          -1,
          "number"),
      new JaninoMetaFunction(
          "bigdecimal",
          "(bigdecimal==null)?null:new java.math.BigDecimal(11.0)",
          ValueMeta.TYPE_BIGNUMBER,
          -1,
          -1,
          "bigdecimal"),
      new JaninoMetaFunction(
          "date",
          "(date==null)?null:new java.util.Date(10000000)",
          ValueMeta.TYPE_DATE,
          -1,
          -1,
          "date"),
      new JaninoMetaFunction(
          "binary",
          "(binary==null)?null:new byte[]{1,2,3,4,5}",
          ValueMeta.TYPE_BINARY,
          -1,
          -1,
          "binary"),
      new JaninoMetaFunction(
          "bool", "(bool==null)?null:Boolean.TRUE", ValueMeta.TYPE_BOOLEAN, -1, -1, "bool"),
    };

    jm.setFormula(formulas);

    transMeta.addTransHop(new TransHopMeta(injectorStep, janinoStep));

    //
    // Create a dummy step
    //
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();

    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);

    TransHopMeta hi = new TransHopMeta(janinoStep, dummyStep);
    transMeta.addTransHop(hi);

    // Now execute the transformation...
    Trans trans = new Trans(transMeta);

    trans.prepareExecution(null);

    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    RowProducer rp = trans.addRowProducer(injectorStepName, 0);

    trans.startThreads();

    for (RowMetaAndData rm : createInputList()) {
      rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();

    trans.waitUntilFinished();

    List<RowMetaAndData> checkList = createExpectedList();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, checkList);
  }