هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

SQL Query

Updated on 2022-08-16 GMT+08:00

Function

Phoenix is an intermediate structured query language (SQL) layer built on HBase. Phoenix provides a JDBC driver that can be embedded in a client. The Phoenix query engine converts input SQL statements to one or multiple HBase scans, and compiles and executes the scan tasks to generate a standard JDBC result set.

Example Code

  • The hbase-example/conf/hbase-site.xml file on the client is used to configure the temporary directory for storing query results. If the client program configures the temporary directory in a Linux environment, configure a Linux path. If the client program configures the temporary directory in a Windows environment, configure a Windows path.
    <property>
         <name>phoenix.spool.directory</name>
         <value>[1] Temporary directory for storing intermediate query results</value>
    </property>
  • JAVA Example: Use the JDBC interface to access HBase.
             public String getURL(Configuration conf) 
              {  
                 String phoenix_jdbc = "jdbc:phoenix"; 
                 String zkQuorum = conf.get("hbase.zookeeper.quorum");      
                 return phoenix_jdbc + ":" + zkQuorum; 
              } 
               
              public void testSQL() 
              { 
                 String tableName = "TEST"; 
                 // Create table 
                 String createTableSQL = "CREATE TABLE IF NOT EXISTS TEST(id integer not null primary key, name varchar, account char(6), birth date)"; 
               
                 // Delete table 
                 String dropTableSQL = "DROP TABLE TEST"; 
               
                 // Insert 
                 String upsertSQL = "UPSERT INTO TEST VALUES(1,'John','100000', TO_DATE('1980-01-01','yyyy-MM-dd'))"; 
               
                 // Query 
                 String querySQL = "SELECT * FROM TEST WHERE id = ?"; 
               
                 // Create the Configuration instance 
                 Configuration conf = getConfiguration(); 
                  
                 // Get URL 
                 String URL = getURL(conf); 
               
                 Connection conn = null; 
                 PreparedStatement preStat = null; 
                 Statement stat = null; 
                 ResultSet result = null; 
               
                 try 
                 { 
                     // Create Connection 
                     conn = DriverManager.getConnection(URL); 
                     // Create Statement 
                     stat = conn.createStatement(); 
                     // Execute Create SQL 
                     stat.executeUpdate(createTableSQL); 
                     // Execute Update SQL 
                     stat.executeUpdate(upsertSQL); 
                     // Create PrepareStatement 
                     preStat = conn.prepareStatement(querySQL); 
                     conn.commit();
                     // Execute query 
                     preStat.setInt(1,1); 
                     result = preStat.executeQuery(); 
                     // Get result 
                     while (result.next())  
                     { 
                         int id = result.getInt("id"); 
                         String name = result.getString(1); 
                     } 
                 }  
                 catch (Exception e) 
                 { 
                     // handler exception 
                 } 
                 finally 
                 { 
                     if(null != result){ 
                          try { 
                              result.close(); 
                              } catch (Exception e2) { 
                                  // handler exception 
                                  } 
                          } 
                     if(null != stat){ 
                         try { 
                             stat.close(); 
                          } catch (Exception e2) { 
                              // handler exception 
                          } 
                     } 
                     if(null != conn){ 
                         try { 
                             conn.close(); 
                          } catch (Exception e2) { 
                              // handler exception 
                          } 
                     } 
                  } 
              }

Precaution

  • You need to configure a temporary directory for storing intermediate query results in hbase-site.xml. The size of the query result set is restricted by the directory size.
  • Phoenix provides most java.sql interfaces and follows the ANSI SQL standard.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback