欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实操指南:Java中SqoopOptions类的运用示例

最编程 2024-07-23 12:40:41
...

实例1: setUp

import com.cloudera.sqoop.SqoopOptions; //导入依赖的package包/类
@Before
public void setUp() {
  super.setUp();

  SqoopOptions options = new SqoopOptions(
      CubridTestUtils.getConnectString(),
      getTableName());
  options.setUsername(CubridTestUtils.getCurrentUser());
  options.setPassword(CubridTestUtils.getPassword());
  this.manager = new CubridManager(options);
  try {
    this.conn = manager.getConnection();
    this.conn.setAutoCommit(false);

  } catch (SQLException sqlE) {
    LOG.error(StringUtils.stringifyException(sqlE));
    fail("Failed with sql exception in setup: " + sqlE);
  }
}
 

实例2: configureDbOutputColumns

import com.cloudera.sqoop.SqoopOptions; //导入依赖的package包/类
@Override
/**
 * {@inheritDoc}
 */
public void configureDbOutputColumns(SqoopOptions options) {
  // In case that we're running upsert, we do not want to
  // change column order as we're actually going to use
  // INSERT INTO ... ON DUPLICATE KEY UPDATE
  // clause.
  if (options.getUpdateMode()
      == SqoopOptions.UpdateMode.AllowInsert) {
    return;
  }

  super.configureDbOutputColumns(options);
}
 

实例3: runImport

import com.cloudera.sqoop.SqoopOptions; //导入依赖的package包/类
/**
 * Run a MapReduce-based import (using the argv provided to control
 * execution).
 */
protected void runImport(SqoopTool tool, String [] argv) throws IOException {
  // run the tool through the normal entry-point.
  int ret;
  try {
    Configuration conf = getConf();
    //Need to disable OraOop for existing tests
    conf.set("oraoop.disabled", "true");
    SqoopOptions opts = getSqoopOptions(conf);
    Sqoop sqoop = new Sqoop(tool, conf, opts);
    ret = Sqoop.runSqoop(sqoop, argv);
  } catch (Exception e) {
    LOG.error("Got exception running Sqoop: " + e.toString());
    e.printStackTrace();
    ret = 1;
  }

  // expect a successful return.
  if (0 != ret) {
    throw new IOException("Failure during job; return status " + ret);
  }
}
 

实例4: testHCatImportWithOnlyHCatKeys

import com.cloudera.sqoop.SqoopOptions; //导入依赖的package包/类
public void testHCatImportWithOnlyHCatKeys() throws Exception {
  String[] args = {
    "--connect",
    "jdbc:db:url",
    "--table",
    "dbtable",
    "--hcatalog-table",
    "table",
    "--hcatalog-partition-keys",
    "k1,k2",
  };
  try {
    SqoopOptions opts = parseImportArgs(args);
    importTool.validateOptions(opts);
    fail("Expected InvalidOptionsException");
  } catch (SqoopOptions.InvalidOptionsException ioe) {
    // expected.
  }
}
 

实例5: testUserMappingFailWhenCantBeApplied

import com.cloudera.sqoop.SqoopOptions; //导入依赖的package包/类
public void testUserMappingFailWhenCantBeApplied() throws Exception {
  String[] args = {
      "--map-column-hive", "id=STRING,value=INTEGER",
  };
  Configuration conf = new Configuration();
  SqoopOptions options =
    new ImportTool().parseArguments(args, null, null, false);
  TableDefWriter writer = new TableDefWriter(options,
      null, HsqldbTestServer.getTableName(), "outputTable", conf, false);

  Map<String, Integer> colTypes = new SqlTypeMap<String, Integer>();
  colTypes.put("id", Types.INTEGER);
  writer.setColumnTypes(colTypes);

  try {
    String createTable = writer.getCreateTableStmt();
    fail("Expected failure on non applied mapping.");
  } catch(IllegalArgumentException iae) {
    // Expected, ok
  }
}