public class DatabaseProduct extends Object implements org.apache.hadoop.conf.Configurable
| Modifier and Type | Class and Description |
|---|---|
static class |
DatabaseProduct.DbType |
| Modifier and Type | Field and Description |
|---|---|
static DatabaseProduct.DbType |
dbType |
static String |
DERBY_NAME |
static String |
MARIADB_NAME |
static String |
MYSQL_NAME |
static String |
ORACLE_NAME |
static String |
POSTGRESQL_NAME |
static String |
SQL_SERVER_NAME |
static String |
UNDEFINED_NAME |
| Modifier | Constructor and Description |
|---|---|
protected |
DatabaseProduct()
Protected constructor for singleton class
|
| Modifier and Type | Method and Description |
|---|---|
String |
addEscapeCharacters(String s) |
String |
addForUpdateClause(String selectStatement) |
String |
addLimitClause(int numRows,
String noSelectsqlQuery)
Add a limit clause to a given query
|
List<String> |
createInsertValuesStmt(String tblColumns,
List<String> rows,
List<Integer> rowsCountInStmts,
org.apache.hadoop.conf.Configuration conf)
Generates "Insert into T(a,b,c) values(1,2,'f'),(3,4,'c')" for appropriate DB.
|
static DatabaseProduct |
determineDatabaseProduct(String productName,
org.apache.hadoop.conf.Configuration conf)
Determine the database product type
|
String |
getBatchInsertQuery(String tableName,
String columns,
String rowFormat,
int batchCount)
Gets the multiple row insert query for the given table with specified columns and row format
|
Object |
getBoolean(boolean val)
Gets the boolean value specific to database for the given input
|
org.apache.hadoop.conf.Configuration |
getConf() |
Map<String,String> |
getDataSourceProperties()
Get datasource properties for connection pools
|
String |
getDBTime()
Returns the query to fetch the current timestamp in milliseconds in the database
|
String |
getHiveSchemaPostfix() |
int |
getMaxRows(int batch,
int paramSize)
Get the max rows in a query with paramSize.
|
String |
getMillisAfterEpochFn()
Get database specific function which returns the milliseconds value after the epoch.
|
String |
getPrepareTxnStmt()
Returns db-specific logic to be executed at the beginning of a transaction.
|
List<String> |
getResetTxnSequenceStmts() |
String |
getTruncateStatement(String name) |
String |
getTxnSeedFn(long seedTxnId) |
protected boolean |
hasJoinOperationOrderBug()
Whether the RDBMS has a bug in join and filter operation order described in DERBY-6358.
|
boolean |
isCUSTOM() |
boolean |
isDeadlock(SQLException e) |
boolean |
isDERBY() |
boolean |
isDuplicateKeyError(Throwable t) |
boolean |
isMYSQL() |
boolean |
isORACLE() |
boolean |
isPOSTGRES() |
static boolean |
isRecoverableException(Throwable t) |
boolean |
isSQLSERVER() |
boolean |
isTableNotExistsError(Throwable t)
Is the given exception a table not found exception
|
boolean |
isUNDEFINED() |
String |
isWithinCheckInterval(String expr,
long intervalInSeconds)
Given an expr (such as a column name) returns a database specific SQL function string
which when executed returns if the value of the expr is within the given interval of
the current timestamp in the database
|
void |
lockInternal()
lockInternal() and
unlockInternal() are used to serialize those operations that require
Select ... |
String |
lockTable(String txnLockTable,
boolean shared)
Returns the SQL query to lock the given table name in either shared/exclusive mode
|
protected boolean |
needsInBatching()
Whether the RDBMS has restrictions on IN list size (explicit, or poor perf-based).
|
static void |
reset() |
void |
setConf(org.apache.hadoop.conf.Configuration c) |
boolean |
supportsGetGeneratedKeys()
Checks if the dbms supports the getGeneratedKeys for multiline insert statements.
|
protected String |
toDate(String tableValue) |
protected String |
toTimestamp(String tableValue) |
void |
unlockInternal() |
public static DatabaseProduct.DbType dbType
public static final String DERBY_NAME
public static final String SQL_SERVER_NAME
public static final String MYSQL_NAME
public static final String MARIADB_NAME
public static final String POSTGRESQL_NAME
public static final String ORACLE_NAME
public static final String UNDEFINED_NAME
protected DatabaseProduct()
public static DatabaseProduct determineDatabaseProduct(String productName, org.apache.hadoop.conf.Configuration conf)
productName - string to defer database connectionpublic static boolean isRecoverableException(Throwable t)
public final boolean isDERBY()
public final boolean isMYSQL()
public final boolean isORACLE()
public final boolean isSQLSERVER()
public final boolean isPOSTGRES()
public final boolean isCUSTOM()
public final boolean isUNDEFINED()
public boolean isDeadlock(SQLException e)
public boolean isTableNotExistsError(Throwable t)
t - Exceptionprotected boolean needsInBatching()
protected boolean hasJoinOperationOrderBug()
public String getHiveSchemaPostfix()
public static void reset()
public String getPrepareTxnStmt()
public String getTxnSeedFn(long seedTxnId)
public String getMillisAfterEpochFn() throws MetaException
MetaException - For unknown database type.public String getDBTime() throws MetaException
MetaException - when the dbType is unknown.public String isWithinCheckInterval(String expr, long intervalInSeconds) throws MetaException
expr - intervalInSeconds - MetaExceptionpublic String addForUpdateClause(String selectStatement) throws MetaException
MetaExceptionpublic String addLimitClause(int numRows, String noSelectsqlQuery) throws MetaException
numRows - noSelectsqlQuery - MetaExceptionpublic String lockTable(String txnLockTable, boolean shared) throws MetaException
txnLockTable - shared - MetaExceptionpublic boolean supportsGetGeneratedKeys()
throws MetaException
MetaExceptionpublic boolean isDuplicateKeyError(Throwable t)
public List<String> createInsertValuesStmt(String tblColumns, List<String> rows, List<Integer> rowsCountInStmts, org.apache.hadoop.conf.Configuration conf)
tblColumns - e.g. "T(a,b,c)"rows - e.g. list of Strings like 3,4,'d'rowsCountInStmts - Output the number of rows in each insert statement returned.conf - public Map<String,String> getDataSourceProperties()
public String getBatchInsertQuery(String tableName, String columns, String rowFormat, int batchCount)
tableName - table name to be used in querycolumns - comma separated column names stringrowFormat - values format string used in the insert query. Format is like (?,?...?) and the number of
question marks in the format is equal to number of column names in the columns argumentbatchCount - number of rows in the querypublic Object getBoolean(boolean val)
val - boolean valuepublic int getMaxRows(int batch,
int paramSize)
batch - the configured batch sizeparamSize - the parameter size in a query statementpublic org.apache.hadoop.conf.Configuration getConf()
getConf in interface org.apache.hadoop.conf.Configurablepublic void setConf(org.apache.hadoop.conf.Configuration c)
setConf in interface org.apache.hadoop.conf.Configurablepublic void lockInternal()
unlockInternal() are used to serialize those operations that require
Select ... For Update to sequence operations properly. In practice that means when running
with Derby database. See more notes at class level.public void unlockInternal()
Copyright © 2024 The Apache Software Foundation. All rights reserved.