public class TxnUtils extends Object
| Constructor and Description |
|---|
TxnUtils() |
| Modifier and Type | Method and Description |
|---|---|
static List<Integer> |
buildQueryWithINClause(org.apache.hadoop.conf.Configuration conf,
List<String> queries,
StringBuilder prefix,
StringBuilder suffix,
Collection<Long> inValues,
String inColumn,
boolean addParens,
boolean notIn)
Build a query (or queries if one query is too big but only for the case of 'IN'
composite clause.
|
static List<Integer> |
buildQueryWithINClauseStrings(org.apache.hadoop.conf.Configuration conf,
List<String> queries,
StringBuilder prefix,
StringBuilder suffix,
List<String> inList,
String inColumn,
boolean addParens,
boolean notIn)
Build a query (or queries if one query is too big but only for the case of 'IN'
composite clause.
|
static String |
createInsertPreparedStmt(String tableName,
List<String> columnNames) |
static String |
createUpdatePreparedStmt(String tableName,
List<String> columnNames,
List<String> conditionKeys) |
static ValidCompactorWriteIdList |
createValidCompactWriteIdList(TableValidWriteIds tableValidWriteIds)
Transform a
TableValidWriteIds to a
ValidCompactorWriteIdList. |
static ValidTxnList |
createValidTxnListForCleaner(GetOpenTxnsResponse txns,
long minOpenTxn,
boolean isAbortCleanup)
Returns a valid txn list for cleaner.
|
static CompactionType |
dbCompactionType2ThriftType(char dbValue) |
static List<Integer> |
executeQueriesInBatch(Statement stmt,
List<String> queries,
int batchSize) |
static void |
executeQueriesInBatchNoCount(DatabaseProduct dbProduct,
Statement stmt,
List<String> queries,
int batchSize)
Calls queries in batch, but does not return affected row numbers.
|
static String |
findUserToRunAs(String location,
Table t,
org.apache.hadoop.conf.Configuration conf)
Determine which user to run an operation as.
|
static long |
generateTemporaryId() |
static String[] |
getDbTableName(String fullTableName) |
static String |
getEpochFn(DatabaseProduct dbProduct)
Get database specific function which returns the milliseconds value after the epoch.
|
static String |
getFullTableName(String dbName,
String tableName)
Should produce the result as <dbName>.<tableName>.
|
static SQLException |
getSqlException(Throwable ex)
Checks is the passed exception, or any of the root (cause) exceptions are an instance of
SQLException. |
static TxnStore |
getTxnStore(org.apache.hadoop.conf.Configuration conf)
Get an instance of the TxnStore that is appropriate for this store
|
static boolean |
isAcidTable(Map<String,String> parameters) |
static boolean |
isAcidTable(Table table)
Should produce the same result as
org.apache.hadoop.hive.ql.io.AcidUtils#isAcidTable.
|
static boolean |
isInsertOnlyTable(Table table) |
static boolean |
isTableSoftDeleteEnabled(Table table,
boolean isSoftDelete) |
static boolean |
isTransactionalTable(Map<String,String> parameters) |
static boolean |
isTransactionalTable(Table table)
Note, users are responsible for using the correct TxnManager.
|
static boolean |
isValidTxn(long txnId) |
static String |
normalizePartitionCase(String s) |
static String |
nvl(String input)
A helper method to return SQL's 'IS NULL'
clause whenever input is NULL.
|
static void |
raiseTxnUnexpectedState(TxnStatus actualStatus,
long txnid)
Used to raise an informative error when the caller expected a txn in a particular TxnStatus
but found it in some other status
|
static void |
seedTxnSequence(Connection conn,
org.apache.hadoop.conf.Configuration conf,
Statement stmt,
long seedTxnId)
Restarts the txnId sequence with the given seed value.
|
static Character |
thriftCompactionType2DbType(CompactionType ct) |
public static ValidTxnList createValidTxnListForCleaner(GetOpenTxnsResponse txns, long minOpenTxn, boolean isAbortCleanup)
txns - Response containing open txns list.minOpenTxn - Minimum open txn which is min open write txn on the table in the case of abort cleanup.isAbortCleanup - Whether the request is for abort cleanup.public static ValidCompactorWriteIdList createValidCompactWriteIdList(TableValidWriteIds tableValidWriteIds)
TableValidWriteIds to a
ValidCompactorWriteIdList. This assumes that the caller intends to
compact the files, and thus treats only open transactions/write ids as invalid. Additionally any
writeId > highestOpenWriteId is also invalid. This is to avoid creating something like
delta_17_120 where writeId 80, for example, is still open.tableValidWriteIds - table write id list from the metastorepublic static TxnStore getTxnStore(org.apache.hadoop.conf.Configuration conf)
conf - configurationpublic static boolean isTransactionalTable(Table table)
public static boolean isAcidTable(Table table)
public static boolean isInsertOnlyTable(Table table)
public static boolean isTableSoftDeleteEnabled(Table table, boolean isSoftDelete)
public static String getFullTableName(String dbName, String tableName)
public static List<Integer> buildQueryWithINClause(org.apache.hadoop.conf.Configuration conf, List<String> queries, StringBuilder prefix, StringBuilder suffix, Collection<Long> inValues, String inColumn, boolean addParens, boolean notIn)
queries - OUT: Array of query stringsprefix - IN: Part of the query that comes before IN listsuffix - IN: Part of the query that comes after IN listinValues - IN: Collection containing IN clause valuesinColumn - IN: single column name of IN list operatoraddParens - IN: add a pair of parenthesis outside the IN lists
e.g. "(id in (1,2,3) OR id in (4,5,6))"notIn - IN: is this for building a 'NOT IN' composite clause?public static List<Integer> buildQueryWithINClauseStrings(org.apache.hadoop.conf.Configuration conf, List<String> queries, StringBuilder prefix, StringBuilder suffix, List<String> inList, String inColumn, boolean addParens, boolean notIn)
queries - IN-OUT: Array of query stringsprefix - IN: Part of the query that comes before IN listsuffix - IN: Part of the query that comes after IN listinList - IN: the list with IN list valuesinColumn - IN: single column name of IN list operatoraddParens - IN: add a pair of parenthesis outside the IN lists
e.g. "(id in (1,2,3) OR id in (4,5,6))"notIn - IN: is this for building a 'NOT IN' composite clause?public static String getEpochFn(DatabaseProduct dbProduct) throws MetaException
dbProduct - The type of the db which is usedMetaException - For unknown database type.public static void executeQueriesInBatchNoCount(DatabaseProduct dbProduct, Statement stmt, List<String> queries, int batchSize) throws SQLException
dbProduct - The type of the db which is usedstmt - Statement which will be used for batching and execution.queries - List of sql queries to execute in a Statement batch.batchSize - maximum number of queries in a single batchSQLException - Thrown if an execution error occurs.public static List<Integer> executeQueriesInBatch(Statement stmt, List<String> queries, int batchSize) throws SQLException
stmt - Statement which will be used for batching and execution.queries - List of sql queries to execute in a Statement batch.batchSize - maximum number of queries in a single batchSQLException - Thrown if an execution error occurs.public static void seedTxnSequence(Connection conn, org.apache.hadoop.conf.Configuration conf, Statement stmt, long seedTxnId) throws SQLException
conn - database connectionstmt - sql statementseedTxnId - the seed value for the sequenceSQLException - expublic static String findUserToRunAs(String location, Table t, org.apache.hadoop.conf.Configuration conf) throws IOException, InterruptedException
location - directory that will be read or written to.t - metastore table objectIOException - if neither the hive metastore user nor the table owner can stat
the location.InterruptedExceptionpublic static CompactionType dbCompactionType2ThriftType(char dbValue) throws SQLException
SQLExceptionpublic static Character thriftCompactionType2DbType(CompactionType ct) throws MetaException
MetaExceptionpublic static String nvl(String input)
input - A string to be compared to null.public static long generateTemporaryId()
public static boolean isValidTxn(long txnId)
public static void raiseTxnUnexpectedState(TxnStatus actualStatus, long txnid) throws NoSuchTxnException, TxnAbortedException
public static SQLException getSqlException(Throwable ex) throws IllegalArgumentException
SQLException.
Returns with the found SQLException or throws an IllegalArgumentException if no SQLException
found in the chain.ex - The exception to checkSQLException found in the exception chain.IllegalArgumentException - Thrown if there is no SQLException in the exception chainpublic static String createUpdatePreparedStmt(String tableName, List<String> columnNames, List<String> conditionKeys)
Copyright © 2024 The Apache Software Foundation. All rights reserved.