コード例 #1
0
  @Test
  public void testNullValueExtracted() throws Exception {

    if (!executor.existTable(nullDataTableName)) {
      executor.executeUpdate(
          "CREATE TABLE "
              + executor.delimitIdentifier(nullDataTableName)
              + "(ICOL INTEGER PRIMARY KEY, DCOL DOUBLE, VCOL VARCHAR(20), DATECOL DATE)");

      for (int i = 0; i < NUMBER_OF_ROWS; i++) {
        int value = i;
        String sql =
            "INSERT INTO "
                + executor.delimitIdentifier(nullDataTableName)
                + " VALUES("
                + value
                + ",null,null,null)";
        executor.executeUpdate(sql);
      }
    }
    MutableContext context = new MutableMapContext();

    LinkConfiguration linkConfig = new LinkConfiguration();

    linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
    linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;

    FromJobConfiguration jobConfig = new FromJobConfiguration();
    context.setString(
        GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL,
        "SELECT * FROM " + executor.delimitIdentifier(nullDataTableName) + " WHERE ${CONDITIONS}");

    Extractor extractor = new GenericJdbcExtractor();
    DummyNullDataWriter writer = new DummyNullDataWriter();
    Schema schema = new Schema("TestExtractor");
    schema
        .addColumn(new FixedPoint("c1", 2L, true))
        .addColumn(new Decimal("c2", 5, 2))
        .addColumn(new Text("c3"))
        .addColumn(new Date("c4"));

    ExtractorContext extractorContext = new ExtractorContext(context, writer, schema);

    GenericJdbcPartition partition = new GenericJdbcPartition();
    partition.setConditions("-50 <= ICOL AND ICOL < -16");
    extractor.extract(extractorContext, linkConfig, jobConfig, partition);
  }
コード例 #2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Test
  public void testSubquery() throws Exception {
    MutableContext context = new MutableMapContext();

    LinkConfiguration linkConfig = new LinkConfiguration();

    linkConfig.linkConfig.jdbcDriver = GenericJdbcTestConstants.DRIVER;
    linkConfig.linkConfig.connectionString = GenericJdbcTestConstants.URL;

    FromJobConfiguration jobConfig = new FromJobConfiguration();

    context.setString(
        GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL,
        "SELECT SQOOP_SUBQUERY_ALIAS.ICOL,SQOOP_SUBQUERY_ALIAS.VCOL,SQOOP_SUBQUERY_ALIAS.DATECOL FROM "
            + "(SELECT * FROM "
            + executor.delimitIdentifier(tableName)
            + " WHERE ${CONDITIONS}) SQOOP_SUBQUERY_ALIAS");

    GenericJdbcPartition partition;

    Extractor extractor = new GenericJdbcExtractor();
    DummyWriter writer = new DummyWriter();
    Schema schema = new Schema("TestExtractor");
    // dummy columns added, all we need is the column count to match to the
    // result set
    schema
        .addColumn(new FixedPoint("c1", 2L, true))
        .addColumn(new Text("c2"))
        .addColumn(new Date("c3"));

    ExtractorContext extractorContext = new ExtractorContext(context, writer, schema);

    partition = new GenericJdbcPartition();
    partition.setConditions("-50 <= ICOL AND ICOL < -16");
    extractor.extract(extractorContext, linkConfig, jobConfig, partition);

    partition = new GenericJdbcPartition();
    partition.setConditions("-16 <= ICOL AND ICOL < 17");
    extractor.extract(extractorContext, linkConfig, jobConfig, partition);

    partition = new GenericJdbcPartition();
    partition.setConditions("17 <= ICOL AND ICOL < 50");
    extractor.extract(extractorContext, linkConfig, jobConfig, partition);
  }