This topic describes how to create a Phoenix5 result table in Realtime Compute for Apache Flink.

Notice
  • This topic applies only to Realtime Compute for Apahce Flink in exclusive node.
  • This topic applies only to Blink 3.4.0 and later.
  • Only Phoenix 5.X is supported.
  • Phoenix is an HBase SQL service deployed on an ApsaraDB for HBase instance. You can use Phoenix only after you activate this service in ApsaraDB for HBase instances.

DDL syntax

In Realtime Compute for Apache Flink, you can use Phoenix5 to store output data. The following code shows an example:
create table US_POPULATION_SINK (
  `STATE` varchar,
  CITY varchar,
  POPULATION BIGINT,
  PRIMARY KEY (`STATE`, CITY)--- The primary key. This field is required. 
) WITH (
  type = 'PHOENIX5',
  serverUrl = '<yourserverUrl>',
  tableName = '<yourTableName>'
);

Parameters in the WITH clause

Parameter Description Required Remarks
type The type of the result table. Yes Set the value to PHOENIX5.
serverUrl The URL of the Phoenix5 query server.
  • If Phoenix5 is created in a cluster, the value of this parameter is the URL of Server Load Balancer (SLB).
  • If Phoenix5 is created on a single server, the value of this parameter is the URL of the server.
Yes You must enable the HBase SQL service in an ApsaraDB for HBase instance.
The value of the serverUrl parameter is in the http://host:port format. In the format:
  • host: indicates the domain name of the Phoenix5 service.
  • port: indicates the port number of the Phoenix5 service. Set the value to 8765.
tableName The name of the Phoenix5 table. Yes The name of the Phoenix5 table is in the SchemaName.TableName format. In the format:
  • SchemaName: indicates the schema name, which can be empty. This means that the schema name is not used and only the table name is used. In this case, the default schema of the database is used.
  • TableName: the name of the table.

Sample code

The following sample code shows how to create a Phoenix5 result table in a Realtime Compute for Apache Flink job.
create table `source` (
  `id` varchar,
  `name` varchar,
  `age` varchar,
  `birthday` varchar 
) WITH (
   type = 'random'
);

create table sink (
  `id` varchar,
  `name` varchar,
  `age` varchar,
  `birthday` varchar,
  primary key (id)
) WITH (
  type = 'PHOENIX5',
  serverUrl = '<yourserverUrl>',
  tableName = '<yourTableName>'
);

INSERT INTO sink
  SELECT  `id` ,`name` , `age` ,`birthday` 
FROM `source`;