Skip to main content

A drop-in replacement for happybase that uses an SQL backend instead of HBase.

Project description

happybase-sql

A (mostly) drop-in replacement for (happybase)[https://happybase.readthedocs.io/en/latest/] that uses an SQL backend instead of HBase.

** Why would I want to use this? **

This project came about when I was working on a legacy project that used a HBase datastore. The HBase cluster became problematic, suffering from performance issues and was expensive to run. After wrestling with HBase for too long, I decided to migrate the data to SQL and wrote this replacement for the happybase library. It's mostly API compatible, so only needed a few minor changes to the code base to swap it in for happybase and thus avoid a lot of time-consuming refactoring. Depending how capital-B Big Data your requirements are, you might find (like I did) that the scale of HBase actually wasn't required, and an SQL DB was plenty big enough, much simpler to administer and a lot cheaper.

Getting started

You'll need to create a table in your SQL database for each of your HBase tables.

Note: currently only Postgres is supported

Here's an example table definition, just replace my_table_name with the name of your table. Note the two indices, one for key uniqueness (which is the equivalent of the HBase row key), and the varchar_pattern_ops index. This is required to allow efficient prefix queries, a feature of HBase key lookups and scans. The data is stored in a JSONB column, where the keys of that JSON data are the HBase column names (e.g. 'cf:col').

CREATE TABLE public."my_table_name" (
	"key" varchar NOT NULL,
	"data" jsonb NOT NULL
);
CREATE UNIQUE INDEX my_table_name_key_idx ON public.my_table_name USING btree (key);
CREATE INDEX my_table_name_key_ops_idx ON public.my_table_name USING btree (key varchar_pattern_ops);

Install the happybase-sql package into your project:

pip install happybase-sql

Create a Connection or ConnectionPool. Note that the host argument is slightly different to happybase, it now refers to the full SQL database URL (including port). The port argument is ignored.

from happybase_sql import ConnectionPool


connection_pool = ConnectionPool(size=3, host='postgresql://localhost:5432/hbase')

with connection_pool.connection() as connection:
    table = connection.table('my_table_name')
    table.put(
        row='abcd',
        data={
            'cf:col1': 'some data',
            'cf:col2': 'some more data',
        },
    )
    row = table.row('abcd')
    print(row)

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

happybase-sql-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

happybase_sql-0.1.0-py2.py3-none-any.whl (6.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file happybase-sql-0.1.0.tar.gz.

File metadata

  • Download URL: happybase-sql-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.6.7-arch1-1

File hashes

Hashes for happybase-sql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b91cd7ba9b06d7d33298b80af57bffe009f5e8e2a3bc52608ec4a77bf25af21
MD5 741e8570e48ef1425a85d52615c71cb2
BLAKE2b-256 e9e8e9e016cc282f5b6d48fcbeea5c824a9486fb36fcecfacdf1382fd3ecfc0b

See more details on using hashes here.

File details

Details for the file happybase_sql-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: happybase_sql-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/5.6.7-arch1-1

File hashes

Hashes for happybase_sql-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 be234d9780a844cedf1855b3c211098f3657fbd5aec10371318a1b858627b063
MD5 f3e98e7aaa46c122fad89d5f70f24868
BLAKE2b-256 f4e623b266633e54d29e8de86c0726d3ff70feb8c74267e1b0ba9bb371e37d4d

See more details on using hashes here.

Supported by

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