Query mapping table information

Updated at:

Use Tablestore SDK for Java to query mapping table schemas, including field names, field types, primary keys, and nullability.

Prerequisites

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 DESCRIBE <mapping_table_name> statement to execute. mapping_table_name specifies the name of the mapping table.

Response

SQLQueryResponse contains the following fields related to the mapping table schema.

Field

Type

Description

type

SQLStatementType

Call getSQLStatementType() to obtain the SQL statement type. SQL_DESCRIBE_TABLE is returned for a DESCRIBE statement.

rows

ByteString

The serialized mapping table schema. Call getSQLResultSet() to obtain the parsed SQLResultSet.

Result set fields

Each row in the SQLResultSet represents a field in the mapping table and contains the following columns.

Field

Type

Description

Field

String

The field name.

Type

String

The SQL data type of the field.

Null

String

Indicates whether the field can be null. Valid values: YES and NO.

Key

String

The key type of the field. PRI indicates a primary key field.

Default

String

The default value of the field. If no default value is configured, null is returned.

Extra

String

Additional field information.