Query mapping table information
Use Tablestore SDK for Java to query mapping table schemas, including field names, field types, primary keys, and nullability.
Prerequisites
Install the Tablestore SDK for Java and initialize a client.
Use Tablestore SDK for Java 5.13.0 or later.
Description
Call the sqlQuery method to execute a DESCRIBE statement and query the field schema of a mapping table.
SQLQueryResponse sqlQuery(SQLQueryRequest request)
The following example queries the field schema of the example_table mapping table and reads each item by field name.
SQLQueryRequest request =
new SQLQueryRequest("DESCRIBE example_table");
SQLQueryResponse response = client.sqlQuery(request);
SQLResultSet resultSet = response.getSQLResultSet();
while (resultSet.hasNext()) {
SQLRow row = resultSet.next();
System.out.println(
row.getString("Field") + ", "
+ row.getString("Type") + ", "
+ row.getString("Null") + ", "
+ row.getString("Key") + ", "
+ row.getString("Default") + ", "
+ row.getString("Extra"));
}
Parameters
SQLQueryRequest contains the following parameter.
|
Name |
Type |
Description |
|
query (required) |
String |
The |
Response
SQLQueryResponse contains the following fields related to the mapping table schema.
|
Field |
Type |
Description |
|
|
SQLStatementType |
Call |
|
|
ByteString |
The serialized mapping table schema. Call |
Result set fields
Each row in the SQLResultSet represents a field in the mapping table and contains the following columns.
|
Field |
Type |
Description |
|
|
String |
The field name. |
|
|
String |
The SQL data type of the field. |
|
|
String |
Indicates whether the field can be null. Valid values: |
|
|
String |
The key type of the field. |
|
|
String |
The default value of the field. If no default value is configured, |
|
|
String |
Additional field information. |