com.cloudera.sqoop.tool
Class BaseSqoopTool

java.lang.Object
  extended by com.cloudera.sqoop.tool.SqoopTool
      extended by com.cloudera.sqoop.tool.BaseSqoopTool
Direct Known Subclasses:
CodeGenTool, CreateHiveTableTool, EvalSqlTool, ExportTool, HelpTool, ImportTool, ListDatabasesTool, ListTablesTool, VersionTool

public abstract class BaseSqoopTool
extends SqoopTool

Layer on top of SqoopTool that provides some basic common code that most SqoopTool implementations will use. Subclasses should call init() at the top of their run() method, and call destroy() at the end in a finally block.


Field Summary
static java.lang.String APPEND_ARG
           
static java.lang.String BIN_OUT_DIR_ARG
           
static java.lang.String CLASS_NAME_ARG
           
static java.lang.String CODE_OUT_DIR_ARG
           
static java.lang.String COLUMNS_ARG
           
static java.lang.String COMPRESS_ARG
           
static java.lang.String COMPRESS_SHORT_ARG
           
static java.lang.String CONNECT_STRING_ARG
           
static java.lang.String DEBUG_SQL_ARG
           
static java.lang.String DEBUG_SQL_SHORT_ARG
           
static java.lang.String DIRECT_ARG
           
static java.lang.String DIRECT_SPLIT_SIZE_ARG
           
static java.lang.String DRIVER_ARG
           
static java.lang.String ENCLOSED_BY_ARG
           
static java.lang.String ESCAPED_BY_ARG
           
static java.lang.String EXPORT_PATH_ARG
           
static java.lang.String FIELDS_TERMINATED_BY_ARG
           
static java.lang.String FMT_SEQUENCEFILE_ARG
           
static java.lang.String FMT_TEXTFILE_ARG
           
static java.lang.String HADOOP_HOME_ARG
           
static java.lang.String HELP_ARG
           
static java.lang.String HELP_STR
           
static java.lang.String HIVE_HOME_ARG
           
static java.lang.String HIVE_IMPORT_ARG
           
static java.lang.String HIVE_OVERWRITE_ARG
           
static java.lang.String HIVE_TABLE_ARG
           
static java.lang.String INLINE_LOB_LIMIT_ARG
           
static java.lang.String INPUT_ENCLOSED_BY_ARG
           
static java.lang.String INPUT_ESCAPED_BY_ARG
           
static java.lang.String INPUT_FIELDS_TERMINATED_BY_ARG
           
static java.lang.String INPUT_LINES_TERMINATED_BY_ARG
           
static java.lang.String INPUT_OPTIONALLY_ENCLOSED_BY_ARG
           
static java.lang.String JAR_FILE_NAME_ARG
           
static java.lang.String LINES_TERMINATED_BY_ARG
           
static org.apache.commons.logging.Log LOG
           
protected  ConnManager manager
           
static java.lang.String MYSQL_DELIMITERS_ARG
           
static java.lang.String NUM_MAPPERS_ARG
           
static java.lang.String NUM_MAPPERS_SHORT_ARG
           
static java.lang.String OPTIONALLY_ENCLOSED_BY_ARG
           
static java.lang.String PACKAGE_NAME_ARG
           
static java.lang.String PASSWORD_ARG
           
static java.lang.String PASSWORD_PROMPT_ARG
           
static java.lang.String SPLIT_BY_ARG
           
static java.lang.String TABLE_ARG
           
static java.lang.String TARGET_DIR_ARG
           
static java.lang.String USERNAME_ARG
           
static java.lang.String VERBOSE_ARG
           
static java.lang.String WAREHOUSE_DIR_ARG
           
static java.lang.String WHERE_ARG
           
 
Fields inherited from class com.cloudera.sqoop.tool.SqoopTool
extraArguments
 
Constructor Summary
BaseSqoopTool()
           
BaseSqoopTool(java.lang.String toolName)
           
 
Method Summary
protected  void applyCodeGenOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out, boolean multiTable)
           
protected  void applyCommonOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out)
          Apply common command-line to the state.
protected  void applyHiveOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out)
           
protected  void applyInputFormatOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out)
           
protected  void applyOutputFormatOptions(org.apache.commons.cli.CommandLine in, SqoopOptions out)
           
protected  void destroy(SqoopOptions sqoopOpts)
          Should be called in a 'finally' block at the end of the run() method.
protected  RelatedOptions getCodeGenOpts(boolean multiTable)
           
protected  RelatedOptions getCommonOptions()
           
protected  RelatedOptions getHiveOptions(boolean explicitHiveImport)
           
protected  RelatedOptions getInputFormatOptions()
           
 ConnManager getManager()
           
protected  RelatedOptions getOutputFormatOptions()
           
protected  java.lang.String[] getSubcommandArgs(java.lang.String[] argv)
          If argv contains an entry "--", return an array containing all elements after the "--" separator.
protected  boolean hasUnrecognizedArgs(java.lang.String[] argv)
           
protected  boolean hasUnrecognizedArgs(java.lang.String[] argv, int offset, int len)
          Examines a subset of the arrray presented, and determines if it contains any non-empty arguments.
protected  boolean init(SqoopOptions sqoopOpts)
          Should be called at the beginning of the run() method to initialize the connection manager, etc.
protected  void setManager(ConnManager mgr)
           
protected  void validateCodeGenOptions(SqoopOptions options)
           
protected  void validateCommonOptions(SqoopOptions options)
           
protected  void validateHiveOptions(SqoopOptions options)
           
protected  void validateOutputFormatOptions(SqoopOptions options)
           
 
Methods inherited from class com.cloudera.sqoop.tool.SqoopTool
appendArgs, applyOptions, configureOptions, getTool, getToolDescription, getToolName, getToolNames, parseArguments, printHelp, run, setToolName, toString, validateOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.commons.logging.Log LOG

HELP_STR

public static final java.lang.String HELP_STR
See Also:
Constant Field Values

CONNECT_STRING_ARG

public static final java.lang.String CONNECT_STRING_ARG
See Also:
Constant Field Values

DRIVER_ARG

public static final java.lang.String DRIVER_ARG
See Also:
Constant Field Values

USERNAME_ARG

public static final java.lang.String USERNAME_ARG
See Also:
Constant Field Values

PASSWORD_ARG

public static final java.lang.String PASSWORD_ARG
See Also:
Constant Field Values

PASSWORD_PROMPT_ARG

public static final java.lang.String PASSWORD_PROMPT_ARG
See Also:
Constant Field Values

DIRECT_ARG

public static final java.lang.String DIRECT_ARG
See Also:
Constant Field Values

TABLE_ARG

public static final java.lang.String TABLE_ARG
See Also:
Constant Field Values

COLUMNS_ARG

public static final java.lang.String COLUMNS_ARG
See Also:
Constant Field Values

SPLIT_BY_ARG

public static final java.lang.String SPLIT_BY_ARG
See Also:
Constant Field Values

WHERE_ARG

public static final java.lang.String WHERE_ARG
See Also:
Constant Field Values

HADOOP_HOME_ARG

public static final java.lang.String HADOOP_HOME_ARG
See Also:
Constant Field Values

HIVE_HOME_ARG

public static final java.lang.String HIVE_HOME_ARG
See Also:
Constant Field Values

WAREHOUSE_DIR_ARG

public static final java.lang.String WAREHOUSE_DIR_ARG
See Also:
Constant Field Values

TARGET_DIR_ARG

public static final java.lang.String TARGET_DIR_ARG
See Also:
Constant Field Values

APPEND_ARG

public static final java.lang.String APPEND_ARG
See Also:
Constant Field Values

FMT_SEQUENCEFILE_ARG

public static final java.lang.String FMT_SEQUENCEFILE_ARG
See Also:
Constant Field Values

FMT_TEXTFILE_ARG

public static final java.lang.String FMT_TEXTFILE_ARG
See Also:
Constant Field Values

HIVE_IMPORT_ARG

public static final java.lang.String HIVE_IMPORT_ARG
See Also:
Constant Field Values

HIVE_TABLE_ARG

public static final java.lang.String HIVE_TABLE_ARG
See Also:
Constant Field Values

HIVE_OVERWRITE_ARG

public static final java.lang.String HIVE_OVERWRITE_ARG
See Also:
Constant Field Values

NUM_MAPPERS_ARG

public static final java.lang.String NUM_MAPPERS_ARG
See Also:
Constant Field Values

NUM_MAPPERS_SHORT_ARG

public static final java.lang.String NUM_MAPPERS_SHORT_ARG
See Also:
Constant Field Values

COMPRESS_ARG

public static final java.lang.String COMPRESS_ARG
See Also:
Constant Field Values

COMPRESS_SHORT_ARG

public static final java.lang.String COMPRESS_SHORT_ARG
See Also:
Constant Field Values

DIRECT_SPLIT_SIZE_ARG

public static final java.lang.String DIRECT_SPLIT_SIZE_ARG
See Also:
Constant Field Values

INLINE_LOB_LIMIT_ARG

public static final java.lang.String INLINE_LOB_LIMIT_ARG
See Also:
Constant Field Values

EXPORT_PATH_ARG

public static final java.lang.String EXPORT_PATH_ARG
See Also:
Constant Field Values

FIELDS_TERMINATED_BY_ARG

public static final java.lang.String FIELDS_TERMINATED_BY_ARG
See Also:
Constant Field Values

LINES_TERMINATED_BY_ARG

public static final java.lang.String LINES_TERMINATED_BY_ARG
See Also:
Constant Field Values

OPTIONALLY_ENCLOSED_BY_ARG

public static final java.lang.String OPTIONALLY_ENCLOSED_BY_ARG
See Also:
Constant Field Values

ENCLOSED_BY_ARG

public static final java.lang.String ENCLOSED_BY_ARG
See Also:
Constant Field Values

ESCAPED_BY_ARG

public static final java.lang.String ESCAPED_BY_ARG
See Also:
Constant Field Values

MYSQL_DELIMITERS_ARG

public static final java.lang.String MYSQL_DELIMITERS_ARG
See Also:
Constant Field Values

INPUT_FIELDS_TERMINATED_BY_ARG

public static final java.lang.String INPUT_FIELDS_TERMINATED_BY_ARG
See Also:
Constant Field Values

INPUT_LINES_TERMINATED_BY_ARG

public static final java.lang.String INPUT_LINES_TERMINATED_BY_ARG
See Also:
Constant Field Values

INPUT_OPTIONALLY_ENCLOSED_BY_ARG

public static final java.lang.String INPUT_OPTIONALLY_ENCLOSED_BY_ARG
See Also:
Constant Field Values

INPUT_ENCLOSED_BY_ARG

public static final java.lang.String INPUT_ENCLOSED_BY_ARG
See Also:
Constant Field Values

INPUT_ESCAPED_BY_ARG

public static final java.lang.String INPUT_ESCAPED_BY_ARG
See Also:
Constant Field Values

CODE_OUT_DIR_ARG

public static final java.lang.String CODE_OUT_DIR_ARG
See Also:
Constant Field Values

BIN_OUT_DIR_ARG

public static final java.lang.String BIN_OUT_DIR_ARG
See Also:
Constant Field Values

PACKAGE_NAME_ARG

public static final java.lang.String PACKAGE_NAME_ARG
See Also:
Constant Field Values

CLASS_NAME_ARG

public static final java.lang.String CLASS_NAME_ARG
See Also:
Constant Field Values

JAR_FILE_NAME_ARG

public static final java.lang.String JAR_FILE_NAME_ARG
See Also:
Constant Field Values

DEBUG_SQL_ARG

public static final java.lang.String DEBUG_SQL_ARG
See Also:
Constant Field Values

DEBUG_SQL_SHORT_ARG

public static final java.lang.String DEBUG_SQL_SHORT_ARG
See Also:
Constant Field Values

VERBOSE_ARG

public static final java.lang.String VERBOSE_ARG
See Also:
Constant Field Values

HELP_ARG

public static final java.lang.String HELP_ARG
See Also:
Constant Field Values

manager

protected ConnManager manager
Constructor Detail

BaseSqoopTool

public BaseSqoopTool()

BaseSqoopTool

public BaseSqoopTool(java.lang.String toolName)
Method Detail

getManager

public ConnManager getManager()

setManager

protected void setManager(ConnManager mgr)

init

protected boolean init(SqoopOptions sqoopOpts)
Should be called at the beginning of the run() method to initialize the connection manager, etc. If this succeeds (returns true), it should be paired with a call to destroy().

Returns:
true on success, false on failure.

destroy

protected void destroy(SqoopOptions sqoopOpts)
Should be called in a 'finally' block at the end of the run() method.


hasUnrecognizedArgs

protected boolean hasUnrecognizedArgs(java.lang.String[] argv,
                                      int offset,
                                      int len)
Examines a subset of the arrray presented, and determines if it contains any non-empty arguments. If so, logs the arguments and returns true.

Parameters:
argv - an array of strings to check.
offset - the first element of the array to check
len - the number of elements to check
Returns:
true if there are any non-null, non-empty argument strings present.

hasUnrecognizedArgs

protected boolean hasUnrecognizedArgs(java.lang.String[] argv)

getSubcommandArgs

protected java.lang.String[] getSubcommandArgs(java.lang.String[] argv)
If argv contains an entry "--", return an array containing all elements after the "--" separator. Otherwise, return null.

Parameters:
argv - a set of arguments to scan for the subcommand arguments.

getCommonOptions

protected RelatedOptions getCommonOptions()
Returns:
RelatedOptions used by most/all Sqoop tools.

getHiveOptions

protected RelatedOptions getHiveOptions(boolean explicitHiveImport)
Parameters:
explicitHiveImport - true if the user has an explicit --hive-import available, or false if this is implied by the tool.
Returns:
options governing interaction with Hive

getOutputFormatOptions

protected RelatedOptions getOutputFormatOptions()
Returns:
options governing output format delimiters

getInputFormatOptions

protected RelatedOptions getInputFormatOptions()
Returns:
options governing input format delimiters.

getCodeGenOpts

protected RelatedOptions getCodeGenOpts(boolean multiTable)
Parameters:
multiTable - true if these options will be used for bulk code-gen.
Returns:
options related to code generation.

applyCommonOptions

protected void applyCommonOptions(org.apache.commons.cli.CommandLine in,
                                  SqoopOptions out)
                           throws SqoopOptions.InvalidOptionsException
Apply common command-line to the state.

Throws:
SqoopOptions.InvalidOptionsException

applyHiveOptions

protected void applyHiveOptions(org.apache.commons.cli.CommandLine in,
                                SqoopOptions out)
                         throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

applyOutputFormatOptions

protected void applyOutputFormatOptions(org.apache.commons.cli.CommandLine in,
                                        SqoopOptions out)
                                 throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

applyInputFormatOptions

protected void applyInputFormatOptions(org.apache.commons.cli.CommandLine in,
                                       SqoopOptions out)
                                throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

applyCodeGenOptions

protected void applyCodeGenOptions(org.apache.commons.cli.CommandLine in,
                                   SqoopOptions out,
                                   boolean multiTable)
                            throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

validateCommonOptions

protected void validateCommonOptions(SqoopOptions options)
                              throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

validateCodeGenOptions

protected void validateCodeGenOptions(SqoopOptions options)
                               throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

validateOutputFormatOptions

protected void validateOutputFormatOptions(SqoopOptions options)
                                    throws SqoopOptions.InvalidOptionsException
Throws:
SqoopOptions.InvalidOptionsException

validateHiveOptions

protected void validateHiveOptions(SqoopOptions options)


Copyright © 2010 Cloudera, Inc.