Apache Phoenix Core library providing SQL-on-HBase functionality with JDBC connectivity, query compilation, and transaction support
npx @tessl/cli install tessl/maven-org-apache-phoenix--phoenix-core@5.2.0Apache Phoenix Core is a SQL engine for Apache HBase that provides JDBC connectivity and SQL query capabilities over HBase. It enables users to interact with HBase using standard SQL syntax while leveraging HBase's scalability and performance characteristics.
Package Name: org.apache.phoenix:phoenix-core
Package Type: Maven Library
Language: Java
Version: 5.2.1
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>5.2.1</version>
</dependency>The main entry points for Phoenix Core require these essential imports:
// Primary JDBC driver
import org.apache.phoenix.jdbc.PhoenixDriver;
import org.apache.phoenix.jdbc.PhoenixConnection;
// Query services
import org.apache.phoenix.query.ConnectionQueryServices;
import org.apache.phoenix.query.QueryServices;
// Schema management
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PMetaData;
// Data types
import org.apache.phoenix.schema.types.PDataType;
// Standard JDBC imports
import java.sql.*;import org.apache.phoenix.jdbc.PhoenixDriver;
import java.sql.*;
// Register the Phoenix driver
Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
// Connect to HBase via Phoenix
String url = "jdbc:phoenix:localhost:2181";
Connection connection = DriverManager.getConnection(url);
// Create a statement
Statement stmt = connection.createStatement();
// Execute queries
ResultSet rs = stmt.executeQuery("SELECT * FROM my_table");
while (rs.next()) {
String name = rs.getString("name");
int value = rs.getInt("value");
// Process results
}Statement stmt = connection.createStatement();
// Create a Phoenix table (maps to HBase table)
stmt.executeUpdate(
"CREATE TABLE users (" +
" id BIGINT NOT NULL, " +
" name VARCHAR, " +
" email VARCHAR, " +
" created_date DATE " +
" CONSTRAINT pk PRIMARY KEY (id))"
);Phoenix Core provides a comprehensive SQL-on-HBase solution with several key architectural components:
Phoenix translates SQL queries into native HBase operations, providing:
Full JDBC 4.0 compliance including:
Phoenix Core provides extensive functionality across multiple domains:
Complete JDBC implementation with Phoenix-specific extensions for HBase integration.
Key Components:
// Driver registration and connection management
PhoenixDriver driver = new PhoenixDriver();
PhoenixConnection connection = driver.connect(url, properties);
// Statement execution with monitoring
PhoenixPreparedStatement stmt = connection.prepareStatement(sql);
PhoenixResultSet results = stmt.executeQuery();Learn more: JDBC API Documentation →
Advanced query compilation framework that transforms SQL into optimized execution plans.
Key Components:
// Query services for metadata and execution
ConnectionQueryServices queryServices = connection.getQueryServices();
// Query compilation and planning
QueryCompiler compiler = new QueryCompiler();
QueryPlan plan = compiler.compile(statement, context);Learn more: Query Compilation Documentation →
Comprehensive schema management with strong typing and metadata caching.
Key Components:
// Table and column metadata
PTable table = connection.getTable(tableName);
PColumn column = table.getColumn(columnName);
// Metadata cache management
PMetaData metaData = connection.getMetaData();
PTableRef tableRef = metaData.getTableRef(tableName);Learn more: Schema and Metadata Documentation →
Rich type system with Phoenix-specific types and array support.
Key Components:
// Core data types
PDataType varchar = PVarchar.INSTANCE;
PDataType integer = PInteger.INSTANCE;
PDataType decimal = PDecimal.INSTANCE;
// Array types
PDataType varcharArray = PVarcharArray.INSTANCE;
PDataType integerArray = PIntegerArray.INSTANCE;Learn more: Data Types Documentation →
Comprehensive exception hierarchy with detailed error codes and messages.
Key Components:
// Exception construction
SQLExceptionInfo.Builder builder = new SQLExceptionInfo.Builder(code);
SQLException exception = builder.setMessage(message).build().buildException();
// Schema-specific exceptions
throw new TableNotFoundException(tableName);
throw new ColumnNotFoundException(columnName);Learn more: Exception Handling Documentation →
Powerful expression system supporting functions, operators, and custom expressions.
Key Components:
// Expression evaluation
Expression expression = LiteralExpression.newConstant(value);
ImmutableBytesWritable result = new ImmutableBytesWritable();
boolean success = expression.evaluate(tuple, result);
// Function expressions
FunctionExpression function = new SomeScalarFunction(arguments);Learn more: Expression Framework Documentation →
Optimized query execution with parallel processing and result iteration.
Key Components:
// Execution planning and iteration
ResultIterator iterator = queryPlan.iterator();
Tuple tuple = iterator.next();
// Mutation state management
MutationState mutationState = connection.getMutationState();
mutationState.commit();Learn more: Query Execution Documentation →
Extensive configuration options and utility classes for Phoenix operations.
Key Components:
// Configuration properties
ConnectionProperty property = ConnectionProperty.QUERY_TIMEOUT;
String value = connection.getClientInfo(property.toString());
// Utility operations
byte[] bytes = ByteUtil.concat(array1, array2);
String formatted = SchemaUtil.getTableName(schemaName, tableName);Learn more: Configuration and Utilities Documentation →
HBase coprocessors and server-side processing for distributed operations.
Key Components:
// Coprocessor interfaces
PhoenixCoprocessor coprocessor = new MetaDataEndpointImpl();
// Index building and management
IndexBuilder indexBuilder = new PhoenixIndexBuilder();
IndexWriter indexWriter = new ParallelWriterIndexCommitter();Learn more: Server-Side Components Documentation →
Native MapReduce support for bulk operations and data processing.
Key Components:
// MapReduce input/output formats
PhoenixInputFormat inputFormat = new PhoenixInputFormat();
PhoenixOutputFormat outputFormat = new PhoenixOutputFormat();
// Bulk loading tools
BulkLoadTool bulkLoader = new BulkLoadTool();Learn more: MapReduce Integration Documentation →
Comprehensive monitoring framework with detailed metrics collection.
Key Components:
// Metrics collection
MetricType metricType = MetricType.QUERY_TIME;
GlobalClientMetrics.GLOBAL_QUERY_TIME.increment(duration);
// Table-specific metrics
TableMetricsManager metricsManager = TableMetricsManager.getInstance();Learn more: Monitoring and Metrics Documentation →
ACID transaction support with Phoenix transaction management.
Key Components:
// Transaction client interfaces
PhoenixTransactionClient txClient = TransactionFactory.getTransactionClient();
// Transaction context management
TransactionContext txContext = txClient.newTransactionContext();Learn more: Transaction Support Documentation →
This documentation is organized into focused sections covering different aspects of Phoenix Core:
Each section provides comprehensive API documentation with practical examples and usage patterns.