A service unit from multiple physical tables is used to associate multiple physical tables and configure metadata for the associated fields. Subsequently, you can develop an API based on this service unit to access data from multiple physical tables simultaneously, achieving union data queries. This topic describes how to create a service unit from multiple physical tables.
Prerequisites
The service unit group has been created. For more information, see Create a Service Project Group.
Metadata creation is necessary when the data source type is HBase 0.9.4/1.1.x/1.2.1/2.x, ElasticSearch, or MongoDB. For more information, see Create Metadata.
Limitations
Metadata configuration for multiple physical tables can be performed through data sources. For supported data sources, see Supported Data Sources for DataService Studio.
Permission policies
Both project administrators and developer users are supported to create service units.
Notes
Only when the field value and field type in the primary physical table and non-primary physical table are the same, can the API created based on this service unit achieve union data queries. Otherwise, union data queries cannot be achieved.
Step 1: select the service unit type
At the top menu bar on the Dataphin home page, select Service > Development.
In the upper left corner, select the project, click the left-side navigation pane Service Unit, on the Service Unit page, click + Create Service Unit.
In the Service Unit Type Selection dialog box, select Multiple Physical Table Service Unit and then click OK.
Step 2: Configure parameters for the service unit from multiple physical tables
On the Create Service Unit page, configure the basic information and parameter information of the service unit.
Service unit basic information configuration
Parameter
Description
Service Unit Name
The name of the service unit. The naming convention is as follows:
Can only contain letters, numbers, and underscores (_).
Starts with a letter.
Length is between 4 and 64 characters.
Service Unit Group
Select the created service unit group.
Mode
The mode is used to define whether the data read by the service unit comes from the development data source or the production data source. The modes include Basic and Dev-Prod modes:
- Basic: In this mode, the service unit can read data only from a data source in the production environment.
- Dev-Prod: In this mode, the service unit can read data from either a data source in the development environment or a data source in the production environment.
You can check the environment where a data source resides on the Data Sources page.
Service Unit Description
Provide a brief description of the service unit. No more than 128 characters.
Max Return Count
The default maximum return count in Dataphin is 1000, with a maximum limit of 10000.
It is used to define the number of records returned when querying data through the API, to avoid excessive data being queried at once, which may cause memory overflow in the Dataphin system. If you need to query more data, you can modify the PageSize parameter value in the SDK for Calling the API to return more data when querying the API.
Add Physical Table
Click Add Physical Table, in the Add New Physical Table dialog box, select data tables based on the data source, and add multiple physical tables that need to read data. For supported data sources, see Supported Data Sources for DataService Studio.
Dataphin defaults to setting the first added physical table as the primary table, but you can also choose another physical table as the primary table.
The calculation logic between multiple physical tables is JOIN. The primary table is the left table in the left join calculation, and other tables are the right tables. Subsequently, you need to select a field from the left table as the foreign key field for multiple physical tables. This field will be used as a parameter when calling the API. If the SQL statement does not contain this field, the API call will fail.
If the existing service unit is similar to the basic information you configured, Dataphin will automatically display the name of the similar service unit for you. You can view the detailed information of the service unit in the service unit list. If you need to continue creating a new service unit, click Continue To Create to enter the Configure Service Unit Fields page.
Configure service unit fields.
Parameter
Description
Configure Service Unit Foreign Key Field
Service Unit Field
You can customize the service unit field name. The naming convention is as follows:
Can only contain letters, numbers, and underscores (_).
Starts with a letter.
Length is between 4 and 64 characters.
Primary Table Name.foreign Key Field (primary Key)
Select a field from the primary table that has the same field value as the associated non-primary table. This foreign key field will be used as a parameter when calling the API. If the SQL statement does not contain this foreign key field, the API call will fail.
Service Unit Foreign Key Field Type
Select the field type of the associated primary table.
Service Unit Field Description
Provide a brief description of the service unit foreign key field.
Configure Service Unit Fields
Service Unit Field Type
The supported field types include Double, Float, String, Date, Boolean, Int, Long, Short, Byte, Bigdecimal, Binary. You need to select the corresponding foreign key field type based on the actual field type of the business data.
If the field type of the business data is not within the above field type range, it is recommended to select String.
Service Unit Field
Configure the mapping of business data fields to the field names in the service unit. You can customize the field name based on the business situation. The naming convention is as follows:
Can only contain letters, numbers, and underscores (_).
Starts with a letter.
Length is between 4 and 64 characters.
Service Unit Field Description
Provide a brief description of the service unit field.
After completing the configuration of the service unit fields, click Data Preview at the bottom to view the business data corresponding to the fields. A maximum of 1000 records can be returned.
Click Submit to complete the creation of the service unit from multiple physical tables.
What to do next
On the service unit page, click the Actions column
icon and select Publish to submit the single physical table service unit to the production environment. You can then create an API based on this single physical table service unit. For more information, see Create an API.
Once the physical table service unit has been created, you can edit, publish, or delete it on the service unit page. For more information, see Manage Service Units.