Skip to main content

StarRocks database adapter for Datus

Project description

datus-starrocks

StarRocks database adapter for Datus.

Overview

StarRocks is a high-performance analytical database that uses the MySQL protocol. This adapter extends the MySQL connector with StarRocks-specific features:

  • Multi-catalog support
  • Materialized views
  • StarRocks-specific metadata queries

Installation

pip install datus-starrocks

This will automatically install the required dependencies:

  • datus-agent
  • datus-mysql (which includes datus-sqlalchemy)

Usage

The adapter is automatically registered with Datus when installed. Configure your database connection:

database:
  type: starrocks
  host: localhost
  port: 9030
  username: root
  password: your_password
  catalog: default_catalog
  database: your_database

Or use programmatically:

from datus_starrocks import StarRocksConnector

# Create connector
connector = StarRocksConnector(
    host="localhost",
    port=9030,
    user="root",
    password="your_password",
    catalog="default_catalog",
    database="mydb"
)

# Use context manager for automatic cleanup
with connector:
    # Test connection
    connector.test_connection()

    # Get catalogs
    catalogs = connector.get_catalogs()
    print(f"Catalogs: {catalogs}")

    # Get databases in catalog
    databases = connector.get_databases(catalog_name="default_catalog")
    print(f"Databases: {databases}")

    # Get tables
    tables = connector.get_tables(catalog_name="default_catalog", database_name="mydb")
    print(f"Tables: {tables}")

    # Get materialized views
    mvs = connector.get_materialized_views(database_name="mydb")
    print(f"Materialized Views: {mvs}")

    # Get materialized views with DDL
    mvs_with_ddl = connector.get_materialized_views_with_ddl(database_name="mydb")
    for mv in mvs_with_ddl:
        print(f"\n{mv['table_name']}:")
        print(mv['definition'])

    # Execute query
    result = connector.execute_query("SELECT * FROM users LIMIT 10")
    print(result.sql_return)

Features

StarRocks-Specific Features

  • Multi-catalog support: Query across multiple catalogs
  • Materialized views: Full support for StarRocks materialized views
  • Catalog management: Switch between catalogs seamlessly

Inherited from MySQL

  • Full CRUD operations (SELECT, INSERT, UPDATE, DELETE)
  • DDL execution (CREATE, ALTER, DROP)
  • Metadata retrieval (tables, views, schemas)
  • Sample data extraction
  • Multiple result formats (pandas, arrow, csv, list)
  • Connection pooling and management

StarRocks-Specific Examples

Working with Catalogs

# List all catalogs
catalogs = connector.get_catalogs()

# Switch catalog
connector.switch_context(catalog_name="hive_catalog")

# Query with explicit catalog
tables = connector.get_tables(
    catalog_name="hive_catalog",
    database_name="my_hive_db"
)

Materialized Views

# Get materialized views
mvs = connector.get_materialized_views(database_name="mydb")

# Get materialized views with full DDL
mvs_with_ddl = connector.get_materialized_views_with_ddl(database_name="mydb")

for mv in mvs_with_ddl:
    print(f"Name: {mv['table_name']}")
    print(f"Database: {mv['database_name']}")
    print(f"Catalog: {mv['catalog_name']}")
    print(f"Definition: {mv['definition']}")

Fully-Qualified Names

StarRocks supports three-part names: catalog.database.table

# Build full name
full_name = connector.full_name(
    catalog_name="default_catalog",
    database_name="mydb",
    table_name="users"
)
# Result: `default_catalog`.`mydb`.`users`

# Query with full name
result = connector.execute_query(f"SELECT * FROM {full_name} LIMIT 10")

Requirements

  • Python >= 3.10
  • StarRocks >= 2.0
  • datus-agent >= 0.3.0
  • datus-mysql >= 0.1.0

Connection Cleanup

The connector includes special handling for PyMySQL cleanup errors that can occur with StarRocks connections. Use the context manager pattern for automatic cleanup:

with StarRocksConnector(...) as connector:
    # Your code here
    pass
# Connection automatically cleaned up

License

Apache License 2.0

Related Packages

  • datus-mysql - MySQL adapter (base for StarRocks)
  • datus-sqlalchemy - SQLAlchemy base connector
  • datus-snowflake - Snowflake adapter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datus_starrocks-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datus_starrocks-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file datus_starrocks-0.1.0.tar.gz.

File metadata

  • Download URL: datus_starrocks-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for datus_starrocks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cee9dad935cfbdd51c2d7f6d9c3193c454da70f7f619c6a62db8f8bfbfb51962
MD5 45e68f97b5a2128b52722a910e91cfd5
BLAKE2b-256 449ec8e451e6d68048cb04fd965fa47efccc77e13bc8c5605fe0a77091d18d4a

See more details on using hashes here.

File details

Details for the file datus_starrocks-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for datus_starrocks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9dd28f11e520ec35470316ddcef8e96eb4aeedcce8c0090403ffbcca70e625e
MD5 e1c0798d067b9ff812d3220a5db53f31
BLAKE2b-256 bf167dcbaae94e8a6efa2699f2f98719ec2bd3ac601022979de678d9a9a1b5a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page