Access LindormTable by using lindorm-cli in HBase mode

Updated at:

In addition to accessing LindormTable through SQL with the MySQL or Avatica protocol, lindorm-cli also provides an HBase-compatible mode. After you connect to LindormTable by using the hbase:// URL format, you can use familiar HBase Shell commands (create, put, get, scan, describe and other commands) to create tables, insert data, and query data. This topic describes how to use lindorm-cli to connect to and use LindormTable in HBase mode.

Prerequisites

  • lindorm-cli is downloaded and installed. For more information, see Installation.

    Note

    HBase mode requires lindorm-cli 2.4.0 or later.

  • The IP address of the client is added to the whitelist of the Lindorm instance. For more information, see Configure a whitelist.

Scenarios and precautions

In most scenarios, we recommend that you use the MySQL protocol (or Avatica protocol) to access LindormTable through SQL: SQL supports complete wide-table capabilities (secondary indexes, multi-column queries, aggregation, pagination, and more), and offers a richer ecosystem and toolchain.

We recommend that you use HBase mode to access LindormTable only in the following scenarios:

  • The tables and data in LindormTable are migrated from open-source HBase: The original tables and data were stored in open-source HBase and have been migrated to LindormTable by using tools such as LTS.

  • You have existing HBase usage habits or scripts: You are familiar with HBase Shell command syntax (create / put / get / scan / describe, etc.) and want to directly use these commands to operate LindormTable without rewriting them as SQL.

  • You need to perform HBase-style table management operations: For example, setting column family properties or managing namespaces.

Connection method

Use a URL in the format of hbase://<host>:<port> to connect to LindormTable (the hbase:// prefix cannot be omitted):

./lindorm-cli -url "hbase://<host>:30020" -username <username>

hbase://<host>:<port> is the connection address for "Access by using HBase Java API" of LindormTable (available in the console under Database Connections > LindormTable). HBase mode requires only a username. The password is optional. If authentication is required, you can pass it through -password or the environment variable LINDORM_PASSWORD. After a successful connection, you can enter HBase commands in the interactive interface.

Note

For more connection methods and parameters (including connections on Windows and the connect subcommand), see Connect to and use the wide table engine with Lindorm-cli.

HBase commands do not end with ;. Press Enter to run each command. To exit the interactive interface, enter exit or quit. You can also run a single command in non-interactive mode by using -execute:

lindorm-cli -url "hbase://<host>:30020" -username <username> -execute "list"

Command reference

lindorm-cli supports a subset of HBase Shell commands in HBase mode, grouped into four categories: DDL, DML Read, DML Write, and Namespace. You can enter help at any time in the interactive interface to view all commands, or help '<command>' to view the detailed usage of a specific command.

Data Definition Language (DDL)

  • list: List all tables. You can optionally use a regular expression to filter table names.

  • create: Create a table (at least one column family must be specified).

  • describe (alias desc): Display detailed information about a specified table, including table properties and column family structure.

  • exists: Verify whether a table exists.

  • disable: Disable a table (take the table offline so it cannot be read or written).

  • enable: Enable a table (bring the table back online).

  • alter: Modify table or column family properties.

  • drop: Delete a specified table (the table must be disabled first).

Data Manipulation Language (DML)

  • put: Write or update the value in a specific cell.

  • get: Get the content of a specified row or cell.

  • delete: Delete the value of a cell in a table (single version).

  • deleteall: Delete all cells of a specified row, column family, or column.

  • scan: Scan and return table data.

  • count: Count and return the number of rows in a table.

Namespace commands

  • create_namespace: Create a namespace.

  • list_namespace: List all namespaces.

  • drop_namespace: Delete a namespace (all tables under it are also deleted).

Operation examples

The following examples use interactive input. In non-interactive mode, pass the command as the value of the -execute parameter.

Create a table and insert data

  1. Create a table. You must specify the table name and column family name.

    # Create a table named test with column family cf
    create 'test', 'cf'

    You can also specify column family attributes in hash format when creating a table, such as VERSIONS:

    create 'test', {NAME => 'cf', VERSIONS => 3}
  2. Insert data.

    put 'test', 'row1', 'cf:a', 'value1'
    put 'test', 'row2', 'cf:b', 'value2'
    put 'test', 'row3', 'cf:c', 'value3'

    In the preceding command, row1 is the row key of the table test, cf:a is the column family and column name, and value1 is the value. The put command can also include an optional timestamp (version number), for example, put 'test','row1','cf:a','value2', 1735689600000.

Query data

  • Query information about all tables. You can use a regular expression to filter table names.

    list
    list 'test'
    list 't.*'
  • Query data from a specified table (scan). scan can be used to scan the entire table or query data within a fixed range.

    scan 'test'

    In the default (table) format, the output uses the native HBase style (ROW / COLUMN+CELL columns):

    ROW                     COLUMN+CELL
    row1                    column=cf:a, timestamp=1735689600000, value=value1
    row2                    column=cf:b, timestamp=1735689600000, value=value2
    row3                    column=cf:c, timestamp=1735689600000, value=value3
    3 row(s) in 0.0230 seconds

    scan supports specifying scan attributes in hash format, such as start row, stop row, limit, and filter:

    scan 'test', {STARTROW => 'row1', STOPROW => 'row3', LIMIT => 100}
    scan 'test', {FILTER => "PrefixFilter('row')"}
  • Query a single row of data from a table (get).

    get 'test', 'row1'

    In the default (table) format, the output includes COLUMN / CELL columns:

    COLUMN                  CELL
    cf:a                    timestamp=1735689600000, value=value1
    1 row(s) in 0.0350 seconds

    You can include hash attributes to read only specified columns: get 'test', 'row1', {COLUMN => 'cf:a'}.

  • Count rows (count).

    count 'test'
    Note

    get / scan in -format json mode renders each cell as one line with fixed fields: row_key / column_family / qualifier / timestamp / value, which facilitates program parsing. The row limit can be controlled by -max-rows (effective for scan).

View table schema (describe)

describe 'test'

In the default (table) format, describe aggregates output by column family in the native HBase style.

Disable and enable tables

To delete a table, modify its settings, or perform other operations, you must first use the disable command to disable the table. After the operation is complete, use the enable command to re-enable it.

disable 'test'
enable 'test'

Delete a table

Delete a specified table (the table must be disabled first):

disable 'test'
drop 'test'

Common configuration

You can use the alter command to adjust common configurations for a table or column family.

# Set data compression algorithm for column family
alter 'test', {NAME => 'cf', COMPRESSION => 'ZSTD'}

# Set the number of versions for column family
alter 'test', {NAME => 'cf', VERSIONS => 5}

# Set TTL for column family (in seconds, 2592000 seconds = 30 days)
alter 'test', {NAME => 'cf', TTL => 2592000}

After modification, you can use describe 'test' to verify whether the changes take effect.

Note

alter and other destructive commands are blocked when -safe-mode is enabled (see Safe mode below). If needed, execute them in a session without safe mode enabled.

Output formats and common parameters

HBase mode reuses the common output formats and security capabilities of lindorm-cli. You can control them through the following parameters (for complete parameter descriptions, see the command-line parameters and subcommands in Connect to and use the wide table engine with Lindorm-cli):

Parameter

Description

-format

Output format. Supported values: column (default) / json / jsonl / csv / vertical / horizontal. In the default table style, get / scan / describe use the native HBase style. json / jsonl output structured data for program parsing.

-max-rows

Limit the maximum number of rows returned by the client. Effective for scan (not effective for get / count).

-safe-mode

Enable safe mode to block destructive commands.

-bytesOutputAsString

Render non-printable bytes as \xHH in the native table style.

-output

Output the execution results of non-interactive mode to a specified file.

Example: Scan in JSON format with safe mode and row limit:

lindorm-cli -url "hbase://<host>:30020" -username user -format json -safe-mode -max-rows 1000 -execute "scan 'test'"

Safe mode

When -safe-mode is enabled in HBase mode, the client blocks the following destructive commands before execution to prevent accidental operations:

Blocked command

Description

disable

Disable a table

drop

Delete a table

truncate / truncate_preserve

Clear a table

alter

Modify a table or column family (the entire command is blocked because it may also delete a column family)

delete

Delete a single-version cell

deleteall

Delete all cells in a row, column family, or column

drop_namespace

Delete a namespace

lindorm-cli -url "hbase://<host>:30020" -username user -safe-mode -execute "drop 'test'"
#output: Operation [DROP] is forbidden by --safe-mode
Note

put / create / enable / create_namespace and other non-destructive commands are not blocked.

FAQ

  • Q: Why can't I connect to LindormTable in HBase mode?

    A: Please verify the following:

    1. The lindorm-cli version is 2.4.0 or later.

    2. The URL is strictly in the format hbase://<host>:<port> and the hbase:// prefix is not omitted.

    3. The connection address used is the one for "Access by using HBase Java API" in the console.

    4. The version of LindormTable is 2.4 or later.

  • Q: Why is the data read garbled?

    A: Please verify that the target table was created through the HBase API or HBase Shell. Do not use HBase mode to access wide tables created through SQL. If you need to access SQL-based wide tables, use the MySQL or Avatica protocol.