实操指南: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
}
}
上一篇: 了解并部署See-SQL审计系统详解
下一篇: docker: Error response from daemon: Conflict. The container name "/sqle-serv
推荐阅读
-
实操示例:在Java中运用ChannelMatcher类
-
实操示例:在Java中运用WebSocketClientProtocolHandler类
-
实操演示:Java中Cosine相似度计算类的运用示例
-
实操指南:Java ESAPI类的运用案例
-
实操指南:Java开发中的工作流流程设计与实现
-
实操指南:Java RowData类的运用案例
-
实操示例:利用Java ConverterManager类的运用方法
-
实操示例:在JavaFX中运用FXGL类
-
实操指南:Java Web Service 中 Feature 类的运用示例
-
实操指南:Java FeatureCollection类的运用示例