public class PhoenixRuntime extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ANNOTATION_ATTRIB_PREFIX
Use this connection property prefix for annotations that you want to show up in traces and log lines emitted by Phoenix.
|
static String |
AUTO_COMMIT_ATTRIB
Use this connection property to explicitly enable or disable auto-commit on a new connection.
|
static String |
BUILD_INDEX_AT_ATTRIB
Internal connection property to force an index to be built at a
given time stamp.
|
static String[] |
CONNECTION_PROPERTIES
All Phoenix specific connection properties
TODO: use enum instead
|
static String |
CONNECTIONLESS
Use this as the zookeeper quorum name to have a connection-less connection.
|
static String |
CONSISTENCY_ATTRIB
Use this connection property to explicitly set read consistency level on a new connection.
|
static String |
CURRENT_SCN_ATTRIB
Use this connection property to control HBase timestamps
by specifying your own long timestamp value at connection time.
|
static String |
EMBEDDED_JDBC_PROTOCOL
Deprecated.
|
static String |
EXPLAIN_PLAN_ESTIMATE_INFO_TS_COLUMN
Use this column name on the row returned by explain plan result set to get timestamp at which
the estimate of number or bytes/rows was collected
|
static String |
EXPLAIN_PLAN_ESTIMATED_BYTES_READ_COLUMN
Use this column name on the row returned by explain plan result set to get estimate of number
of bytes read.
|
static String |
EXPLAIN_PLAN_ESTIMATED_ROWS_READ_COLUMN
Use this column name on the row returned by explain plan result set to get estimate of number
of rows read.
|
static String |
JDBC_PROTOCOL
Root for the JDBC URL that the Phoenix accepts accepts.
|
static char |
JDBC_PROTOCOL_SEPARATOR |
static char |
JDBC_PROTOCOL_TERMINATOR |
static String |
JDBC_THIN_PROTOCOL
Root for the JDBC URL used by the thin driver.
|
static String |
NO_UPGRADE_ATTRIB
Use this connection property to prevent an upgrade from occurring when
connecting to a new server version.
|
static String |
PHOENIX_TEST_DRIVER_URL_PARAM |
static String |
REQUEST_METRIC_ATTRIB
Use this connection property to explicitly enable or disable request level metric collection.
|
static String |
SCHEMA_ATTRIB |
static String |
TENANT_ID_ATTRIB
Use this connection property to help with fairness of resource allocation
for the client and server.
|
static String |
UPSERT_BATCH_SIZE_ATTRIB
Use this connection property to control the number of rows that are
batched together on an UPSERT INTO table1...
|
static String |
UPSERT_BATCH_SIZE_BYTES_ATTRIB
Use this connection property to control the number of bytes that are
batched together on an UPSERT INTO table1...
|
Modifier and Type | Method and Description |
---|---|
static boolean |
areGlobalClientMetricsBeingCollected() |
static Object[] |
decodeColumnValues(Connection conn,
String fullTableName,
byte[] value,
List<Pair<String,String>> columns) |
static Object[] |
decodeValues(Connection conn,
String fullTableName,
byte[] value,
List<Pair<String,String>> columns)
Deprecated.
|
static byte[] |
encodeColumnValues(Connection conn,
String fullTableName,
Object[] values,
List<Pair<String,String>> columns) |
static byte[] |
encodeValues(Connection conn,
String fullTableName,
Object[] values,
List<Pair<String,String>> columns)
Deprecated.
|
static int |
executeStatements(Connection conn,
Reader reader,
List<Object> binds)
Runs a series of semicolon-terminated SQL statements using the connection provided, returning
the number of SQL statements executed.
|
static List<ColumnInfo> |
generateColumnInfo(Connection conn,
String tableName,
List<String> columns)
Get list of ColumnInfos that contain Column Name and its associated
PDataType for an import.
|
static String |
getArraySqlTypeName(Integer maxLength,
Integer scale,
PDataType arrayType) |
static ColumnInfo |
getColumnInfo(PColumn pColumn)
Constructs a column info for the supplied pColumn
|
static ColumnInfo |
getColumnInfo(PTable table,
String columnName)
Returns the column info for the given column for the given table.
|
static long |
getCurrentScn(ReadOnlyProps props) |
static Expression |
getFirstPKColumnExpression(Connection conn,
String fullTableName)
Get expression that may be used to evaluate to the value of the first
column of a given row in a Phoenix table.
|
static Collection<GlobalMetric> |
getGlobalPhoenixClientMetrics()
Exposes the various internal phoenix metrics collected at the client JVM level.
|
static int |
getLimit(QueryPlan plan) |
static QueryPlan |
getOptimizedQueryPlan(PreparedStatement stmt)
Returns the opitmized query plan used by phoenix for executing the sql.
|
static Map<MetricType,Long> |
getOverAllReadRequestMetricInfo(ResultSet rs)
Method to expose the overall metrics associated with executing a query via phoenix.
|
static Map<String,Long> |
getOverAllReadRequestMetrics(ResultSet rs)
Deprecated.
|
static void |
getPkColsDataTypesForSql(List<Pair<String,String>> columns,
List<String> dataTypes,
QueryPlan plan,
Connection conn,
boolean forDataTable)
Deprecated.
|
static List<Pair<String,String>> |
getPkColsForSql(Connection conn,
QueryPlan plan)
Get the column family, column name pairs that make up the row key of the table that will be queried.
|
static void |
getPkColsForSql(List<Pair<String,String>> columns,
QueryPlan plan,
Connection conn,
boolean forDataTable)
Deprecated.
|
static Map<String,Map<MetricType,Long>> |
getReadMetricInfoForMutationsSinceLastReset(Connection conn)
Method to expose the read metrics associated with executing a dml statement.
|
static Map<String,Map<String,Long>> |
getReadMetricsForMutationsSinceLastReset(Connection conn)
Deprecated.
|
static Map<String,Map<MetricType,Long>> |
getRequestReadMetricInfo(ResultSet rs)
Method to expose the metrics associated with performing reads using the passed result set.
|
static Map<String,Map<String,Long>> |
getRequestReadMetrics(ResultSet rs)
Deprecated.
|
static String |
getSqlTypeName(PColumn pCol) |
static String |
getSqlTypeName(PDataType dataType,
Integer maxLength,
Integer scale) |
static PTable |
getTable(Connection conn,
String name)
Returns the table if it is found in the connection metadata cache.
|
static PTable |
getTableNoCache(Connection conn,
String name) |
static Expression |
getTenantIdExpression(Connection conn,
String fullTableName)
Get expression that may be used to evaluate the tenant ID of a given row in a
multi-tenant table.
|
static List<KeyValue> |
getUncommittedData(Connection conn)
Deprecated.
|
static Iterator<Pair<byte[],List<KeyValue>>> |
getUncommittedDataIterator(Connection conn)
Get the list of uncommitted KeyValues for the connection.
|
static Iterator<Pair<byte[],List<KeyValue>>> |
getUncommittedDataIterator(Connection conn,
boolean includeMutableIndexes)
Get the list of uncommitted KeyValues for the connection.
|
static long |
getWallClockTimeFromCellTimeStamp(long tsOfCell)
Use this utility function to ensure that a timestamp is in milliseconds across transactional and
non transactional tables.
|
static Map<String,Map<MetricType,Long>> |
getWriteMetricInfoForMutationsSinceLastReset(Connection conn)
Method to expose the metrics associated with sending over mutations to HBase.
|
static Map<String,Map<String,Long>> |
getWriteMetricsForMutationsSinceLastReset(Connection conn)
Deprecated.
|
static boolean |
hasOrderBy(QueryPlan plan)
Whether or not the query plan has any order by expressions.
|
static void |
main(String[] args)
Provides a mechanism to run SQL scripts against, where the arguments are:
1) connection URL string
2) one or more paths to either SQL scripts or CSV files
If a CurrentSCN property is set on the connection URL, then it is incremented
between processing, with each file being processed by a new connection at the
increment timestamp value.
|
static void |
resetMetrics(Connection conn)
Reset the mutation and reads-for-mutations metrics collected in the connection.
|
static void |
resetMetrics(ResultSet rs)
Reset the read metrics collected in the result set.
|
public static final String JDBC_PROTOCOL
public static final String JDBC_THIN_PROTOCOL
public static final char JDBC_PROTOCOL_TERMINATOR
public static final char JDBC_PROTOCOL_SEPARATOR
@Deprecated public static final String EMBEDDED_JDBC_PROTOCOL
public static final String CURRENT_SCN_ATTRIB
public static final String BUILD_INDEX_AT_ATTRIB
public static final String TENANT_ID_ATTRIB
QueryServices
configuration propertiespublic static final String NO_UPGRADE_ATTRIB
public static final String UPSERT_BATCH_SIZE_ATTRIB
public static final String UPSERT_BATCH_SIZE_BYTES_ATTRIB
public static final String AUTO_COMMIT_ATTRIB
public static final String CONSISTENCY_ATTRIB
public static final String REQUEST_METRIC_ATTRIB
public static final String EXPLAIN_PLAN_ESTIMATED_BYTES_READ_COLUMN
public static final String EXPLAIN_PLAN_ESTIMATED_ROWS_READ_COLUMN
public static final String EXPLAIN_PLAN_ESTIMATE_INFO_TS_COLUMN
public static final String[] CONNECTION_PROPERTIES
public static final String CONNECTIONLESS
getUncommittedData(Connection)
public static final String ANNOTATION_ATTRIB_PREFIX
public static final String PHOENIX_TEST_DRIVER_URL_PARAM
public static final String SCHEMA_ATTRIB
public static void main(String[] args)
public static int executeStatements(Connection conn, Reader reader, List<Object> binds) throws IOException, SQLException
CURRENT_SCN_ATTRIB
connection property, then the timestamp
is bumped up by one after each statement execution.conn
- an open JDBC connectionreader
- a reader for semicolumn separated SQL statementsbinds
- the binds for all statementsIOException
SQLException
@Deprecated public static List<KeyValue> getUncommittedData(Connection conn) throws SQLException
conn
- an open JDBC connectionSQLException
public static Iterator<Pair<byte[],List<KeyValue>>> getUncommittedDataIterator(Connection conn) throws SQLException
conn
- an open JDBC connectionSQLException
public static Iterator<Pair<byte[],List<KeyValue>>> getUncommittedDataIterator(Connection conn, boolean includeMutableIndexes) throws SQLException
conn
- an open JDBC connectionSQLException
public static PTable getTableNoCache(Connection conn, String name) throws SQLException
SQLException
public static PTable getTable(Connection conn, String name) throws SQLException
conn
- name
- requires a pre-normalized table name or a pre-normalized schema and table nameSQLException
public static List<ColumnInfo> generateColumnInfo(Connection conn, String tableName, List<String> columns) throws SQLException
conn
- Phoenix connection from which metadata will be readtableName
- Phoenix table name whose columns are to be checked. Can include a schema
namecolumns
- user-supplied list of import columns, can be nullSQLException
public static ColumnInfo getColumnInfo(PTable table, String columnName) throws SQLException
table
- columnName
- User-specified column name. May be family-qualified or bare.SQLException
- if parameters are null or if column is not found or if column is ambiguous.public static ColumnInfo getColumnInfo(PColumn pColumn) throws SQLException
pColumn
- SQLException
- if the parameter is null.public static QueryPlan getOptimizedQueryPlan(PreparedStatement stmt) throws SQLException
stmt
- to return the plan forSQLException
public static boolean hasOrderBy(QueryPlan plan)
plan
- public static int getLimit(QueryPlan plan)
public static List<Pair<String,String>> getPkColsForSql(Connection conn, QueryPlan plan) throws SQLException
conn
- - connection used to generate the query plan. Caller should take care of closing the connection appropriately.plan
- - query plan to get info for.SQLException
@Deprecated public static void getPkColsForSql(List<Pair<String,String>> columns, QueryPlan plan, Connection conn, boolean forDataTable) throws SQLException
columns
- - Initialized empty list to be filled with the pairs of column family name and column name for columns that are used
as row key for the query plan. Column family names are optional and hence the first part of the pair is nullable.
Column names and family names are enclosed in double quotes to allow for case sensitivity and for presence of
special characters. Salting column and view index id column are not included. If the connection is tenant specific
and the table used by the query plan is multi-tenant, then the tenant id column is not included as well.plan
- - query plan to get info for.conn
- - connection used to generate the query plan. Caller should take care of closing the connection appropriately.forDataTable
- - if true, then family names and column names correspond to the data table even if the query plan uses
the secondary index table. If false, and if the query plan uses the secondary index table, then the family names and column
names correspond to the index table.SQLException
@Deprecated public static void getPkColsDataTypesForSql(List<Pair<String,String>> columns, List<String> dataTypes, QueryPlan plan, Connection conn, boolean forDataTable) throws SQLException
columns
- - Initialized empty list to be filled with the pairs of column family name and column name for columns that are used
as row key for the query plan. Column family names are optional and hence the first part of the pair is nullable.
Column names and family names are enclosed in double quotes to allow for case sensitivity and for presence of
special characters. Salting column and view index id column are not included. If the connection is tenant specific
and the table used by the query plan is multi-tenant, then the tenant id column is not included as well.dataTypes
- - Initialized empty list to be filled with the corresponding data type for the columns in @param columns.plan
- - query plan to get info forconn
- - phoenix connection used to generate the query plan. Caller should take care of closing the connection appropriately.forDataTable
- - if true, then column names and data types correspond to the data table even if the query plan uses
the secondary index table. If false, and if the query plan uses the secondary index table, then the column names and data
types correspond to the index table.SQLException
public static String getSqlTypeName(PColumn pCol)
pCol
- public static String getSqlTypeName(PDataType dataType, Integer maxLength, Integer scale)
public static String getArraySqlTypeName(@Nullable Integer maxLength, @Nullable Integer scale, PDataType arrayType)
@Deprecated public static byte[] encodeValues(Connection conn, String fullTableName, Object[] values, List<Pair<String,String>> columns) throws SQLException
conn
- connection that was used for reading/generating value.fullTableName
- fully qualified table namevalues
- values of the columnscolumns
- list of pair of column that includes column family as first part and column name as the second part.
Column family is optional and hence nullable. Columns in the list have to be in the same order as the order of occurence
of their values in the object array.SQLException
#decodeValues(Connection, String, byte[], List)}
@Deprecated public static Object[] decodeValues(Connection conn, String fullTableName, byte[] value, List<Pair<String,String>> columns) throws SQLException
conn
- connection that was used for reading/generating value.fullTableName
- fully qualified table namevalue
- byte value of the columns concatenated as a single byte array. @see encodeColumnValues(Connection, String, Object[], List)
columns
- list of column names for the columns that have their respective values
present in the byte array. The column names should be in the same order as their values are in the byte array.
The column name includes both family name, if present, and column name.SQLException
public static byte[] encodeColumnValues(Connection conn, String fullTableName, Object[] values, List<Pair<String,String>> columns) throws SQLException
conn
- connection that was used for reading/generating value.fullTableName
- fully qualified table namevalues
- values of the columnscolumns
- list of pair of column that includes column family as first part and column name as the second part.
Column family is optional and hence nullable. Columns in the list have to be in the same order as the order of occurence
of their values in the object array.SQLException
#decodeValues(Connection, String, byte[], List)}
public static Object[] decodeColumnValues(Connection conn, String fullTableName, byte[] value, List<Pair<String,String>> columns) throws SQLException
conn
- connection that was used for reading/generating value.fullTableName
- fully qualified table namevalue
- byte value of the columns concatenated as a single byte array. @see encodeColumnValues(Connection, String, Object[], List)
columns
- list of column names for the columns that have their respective values
present in the byte array. The column names should be in the same order as their values are in the byte array.
The column name includes both family name, if present, and column name.SQLException
public static Expression getTenantIdExpression(Connection conn, String fullTableName) throws SQLException
conn
- open Phoenix connectionfullTableName
- full table nameSQLException
- if the table name is not found, a TableNotFoundException
is thrown. If a multi-tenant local index is supplied a SQLFeatureNotSupportedException
is thrown.public static Expression getFirstPKColumnExpression(Connection conn, String fullTableName) throws SQLException
conn
- open Phoenix connectionfullTableName
- full table nameSQLException
- if the table name is not found, a TableNotFoundException
is thrown. If a local index is supplied a SQLFeatureNotSupportedException
is thrown.public static Collection<GlobalMetric> getGlobalPhoenixClientMetrics()
public static boolean areGlobalClientMetricsBeingCollected()
public static Map<String,Map<MetricType,Long>> getRequestReadMetricInfo(ResultSet rs) throws SQLException
Map> overAllQueryMetrics = null; Map > requestReadMetrics = null; try (ResultSet rs = stmt.executeQuery()) { while(rs.next()) { ..... } overAllQueryMetrics = PhoenixRuntime.getOverAllReadRequestMetrics(rs); requestReadMetrics = PhoenixRuntime.getRequestReadMetrics(rs); PhoenixRuntime.resetMetrics(rs); }
rs
- result set to get the metrics forSQLException
@Deprecated public static Map<String,Map<String,Long>> getRequestReadMetrics(ResultSet rs) throws SQLException
SQLException
public static Map<MetricType,Long> getOverAllReadRequestMetricInfo(ResultSet rs) throws SQLException
Map> overAllQueryMetrics = null; Map > requestReadMetrics = null; try (ResultSet rs = stmt.executeQuery()) { while(rs.next()) { ..... } overAllQueryMetrics = PhoenixRuntime.getOverAllReadRequestMetrics(rs); requestReadMetrics = PhoenixRuntime.getRequestReadMetrics(rs); PhoenixRuntime.resetMetrics(rs); }
rs
- result set to get the metrics forSQLException
@Deprecated public static Map<String,Long> getOverAllReadRequestMetrics(ResultSet rs) throws SQLException
SQLException
public static Map<String,Map<MetricType,Long>> getWriteMetricInfoForMutationsSinceLastReset(Connection conn) throws SQLException
resetMetrics(Connection)
is called or the connection is closed. Example usage:
Map> mutationWriteMetrics = null; Map > mutationReadMetrics = null; try (Connection conn = DriverManager.getConnection(url)) { conn.createStatement.executeUpdate(dml1); .... conn.createStatement.executeUpdate(dml2); ... conn.createStatement.executeUpdate(dml3); ... conn.commit(); mutationWriteMetrics = PhoenixRuntime.getWriteMetricsForMutationsSinceLastReset(conn); mutationReadMetrics = PhoenixRuntime.getReadMetricsForMutationsSinceLastReset(conn); PhoenixRuntime.resetMetrics(rs); }
conn
- connection to get the metrics forSQLException
@Deprecated public static Map<String,Map<String,Long>> getWriteMetricsForMutationsSinceLastReset(Connection conn) throws SQLException
SQLException
public static Map<String,Map<MetricType,Long>> getReadMetricInfoForMutationsSinceLastReset(Connection conn) throws SQLException
resetMetrics(Connection)
is
called or the connection is closed. Example usage:
Map> mutationWriteMetrics = null; Map > mutationReadMetrics = null; try (Connection conn = DriverManager.getConnection(url)) { conn.createStatement.executeUpdate(dml1); .... conn.createStatement.executeUpdate(dml2); ... conn.createStatement.executeUpdate(dml3); ... conn.commit(); mutationWriteMetrics = PhoenixRuntime.getWriteMetricsForMutationsSinceLastReset(conn); mutationReadMetrics = PhoenixRuntime.getReadMetricsForMutationsSinceLastReset(conn); PhoenixRuntime.resetMetrics(rs); }
conn
- connection to get the metrics forSQLException
@Deprecated public static Map<String,Map<String,Long>> getReadMetricsForMutationsSinceLastReset(Connection conn) throws SQLException
SQLException
public static void resetMetrics(ResultSet rs) throws SQLException
rs
- SQLException
#getRequestReadMetrics(ResultSet)} {@link #getOverAllReadRequestMetrics(ResultSet)}
public static void resetMetrics(Connection conn) throws SQLException
conn
- SQLException
#getReadMetricsForMutationsSinceLastReset(Connection)} {@link #getWriteMetricsForMutationsSinceLastReset(Connection)}
public static long getWallClockTimeFromCellTimeStamp(long tsOfCell)
tsOfCell
- Cell time stamp to be converted.public static long getCurrentScn(ReadOnlyProps props)
Copyright © 2019 Apache Software Foundation. All Rights Reserved.