public class GenericJdbcDatabaseAccessor extends Object implements DatabaseAccessor
| Modifier and Type | Field and Description |
|---|---|
protected static String |
DBCP_CONFIG_PREFIX |
protected DataSource |
dbcpDataSource |
protected static int |
DEFAULT_FETCH_SIZE |
protected static org.slf4j.Logger |
LOGGER |
| Constructor and Description |
|---|
GenericJdbcDatabaseAccessor() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
addBoundaryToQuery(String tableName,
String sql,
String partitionColumn,
String lowerBound,
String upperBound) |
protected String |
addLimitAndOffsetToQuery(String sql,
int limit,
int offset)
Uses generic JDBC escape functions to add a limit and offset clause to a query string
|
protected String |
addLimitToQuery(String sql,
int limit) |
protected void |
cleanupResources(Connection conn,
PreparedStatement ps,
ResultSet rs) |
protected String |
constructQuery(String table,
String[] columnNames)
Constructs the query used as the prepared statement to insert data.
|
org.apache.commons.lang3.tuple.Pair<String,String> |
getBounds(org.apache.hadoop.conf.Configuration conf,
String partitionColumn,
boolean retrieveMin,
boolean retrieveMax) |
List<String> |
getColumnNames(org.apache.hadoop.conf.Configuration conf) |
List<TypeInfo> |
getColumnTypes(org.apache.hadoop.conf.Configuration conf)
Returns a list of types for the columns in the specified configuration.
|
protected Properties |
getConnectionPoolProperties(org.apache.hadoop.conf.Configuration conf) |
protected Properties |
getDefaultDBCPProperties() |
protected int |
getFetchSize(org.apache.hadoop.conf.Configuration conf) |
protected String |
getMetaDataQuery(String sql) |
JdbcRecordIterator |
getRecordIterator(org.apache.hadoop.conf.Configuration conf,
String partitionColumn,
String lowerBound,
String upperBound,
int limit,
int offset) |
org.apache.hadoop.mapreduce.RecordWriter |
getRecordWriter(org.apache.hadoop.mapreduce.TaskAttemptContext context) |
int |
getTotalNumberOfRecords(org.apache.hadoop.conf.Configuration conf) |
protected void |
initializeDatabaseConnection(org.apache.hadoop.conf.Configuration conf) |
boolean |
needColumnQuote() |
protected static final String DBCP_CONFIG_PREFIX
protected static final int DEFAULT_FETCH_SIZE
protected static final org.slf4j.Logger LOGGER
protected DataSource dbcpDataSource
public List<String> getColumnNames(org.apache.hadoop.conf.Configuration conf) throws HiveJdbcDatabaseAccessException
getColumnNames in interface DatabaseAccessorHiveJdbcDatabaseAccessExceptionpublic List<TypeInfo> getColumnTypes(org.apache.hadoop.conf.Configuration conf) throws HiveJdbcDatabaseAccessException
DatabaseAccessorTypeInfoFactory.unknownTypeInfo is used.
There is a one-to-one correspondence between the types returned in this method and the column
names obtained with DatabaseAccessor.getColumnNames(Configuration).
Implementors of the method can derive the types by querying the database, exploit the state
of the accessor, or use the configuration.getColumnTypes in interface DatabaseAccessorHiveJdbcDatabaseAccessException - if some error occurs while accessing the databasepublic int getTotalNumberOfRecords(org.apache.hadoop.conf.Configuration conf)
throws HiveJdbcDatabaseAccessException
getTotalNumberOfRecords in interface DatabaseAccessorHiveJdbcDatabaseAccessExceptionpublic JdbcRecordIterator getRecordIterator(org.apache.hadoop.conf.Configuration conf, String partitionColumn, String lowerBound, String upperBound, int limit, int offset) throws HiveJdbcDatabaseAccessException
getRecordIterator in interface DatabaseAccessorHiveJdbcDatabaseAccessExceptionpublic org.apache.hadoop.mapreduce.RecordWriter getRecordWriter(org.apache.hadoop.mapreduce.TaskAttemptContext context)
throws IOException
getRecordWriter in interface DatabaseAccessorIOExceptionprotected String constructQuery(String table, String[] columnNames)
table - the table to insert intocolumnNames - the columns to insert intoprotected String addLimitAndOffsetToQuery(String sql, int limit, int offset)
sql - limit - offset - protected String addBoundaryToQuery(String tableName, String sql, String partitionColumn, String lowerBound, String upperBound)
protected void cleanupResources(Connection conn, PreparedStatement ps, ResultSet rs)
protected void initializeDatabaseConnection(org.apache.hadoop.conf.Configuration conf)
throws Exception
Exceptionprotected Properties getConnectionPoolProperties(org.apache.hadoop.conf.Configuration conf) throws Exception
Exceptionprotected Properties getDefaultDBCPProperties()
protected int getFetchSize(org.apache.hadoop.conf.Configuration conf)
public org.apache.commons.lang3.tuple.Pair<String,String> getBounds(org.apache.hadoop.conf.Configuration conf, String partitionColumn, boolean retrieveMin, boolean retrieveMax) throws HiveJdbcDatabaseAccessException
getBounds in interface DatabaseAccessorHiveJdbcDatabaseAccessExceptionpublic boolean needColumnQuote()
needColumnQuote in interface DatabaseAccessorCopyright © 2022 The Apache Software Foundation. All rights reserved.