This release is a pre-release and may not be stable for production use.
Hologres DataFrame API (Python)
A lazy, pandas-style DataFrame API for Hologres. Chain transformations in Python; the library compiles them into a single PostgreSQL statement and pushes it down to Hologres, so computation stays in the engine and only results come back.
Naming and execution model follow Snowpark for Python,
with snake_case only (group_by, never groupBy) and PostgreSQL semantics.
Install
pip install --pre hologres-dataframe
The 0.1.0.dev0 pre-release requires hologres-client>=0.1.2.dev0, so the
matching client pre-release must be available from the same package index.
For development from this repository:
pip install -e ".[dev]"
pandas and pyarrow are optional; they are only needed for to_pandas(),
from_pandas() and local read_files().
Function Compute deployment is also optional:
pip install "hologres-dataframe[fc]"
Quickstart
import hologres.dataframe as hg
session = hg.connect(
host="xxx.hologres.aliyuncs.com",
port=80,
dbname="my_db",
user="<access_id>",
password="<access_key>",
)
(
session.table("public.orders")
.filter(hg.col("amount") > 100) # WHERE amount > 100
.with_column("tax", hg.col("amount") * 0.06) # amount * 0.06 AS tax
.select("order_id", "region", "amount", "tax")
.sort(hg.col("amount"), ascending=False) # ORDER BY amount DESC
.show(10)
) # <- the only step that runs SQL
Everything before show() is lazy: transformations just build a logical plan.
Actions (show, collect, to_pandas, count, first, take, iter_rows,
write, write_files, as_dynamic_table) are what trigger
execution. session.refresh_table() also executes immediately.
Like Snowpark, in-memory DataFrames should normally be created from a Session so the returned DataFrame already knows where actions and writes should execute:
df = session.from_dict({"id": [1, 2], "name": ["a", "b"]})
df.write("public.target")
The top-level hg.from_dict and hg.from_records functions remain available
for unbound SQL construction and compatibility. The legacy top-level
hg.from_pandas entry still accepts session=...; new code should use
session.from_pandas(pdf). An unbound DataFrame can be compiled, but it cannot
execute an action or write until it is created through a Session-bound entry
point.
Materialize a lazy query as a Dynamic Table with safe create-if-absent behavior by default:
summary = session.table("public.orders").select("order_id", "region", "amount")
summary.as_dynamic_table(
"public.dt_orders",
freshness="10 minutes",
refresh_mode="incremental",
options={"cdc_format": "binlog"},
)
session.refresh_table("public.dt_orders")
Use mode="errorifexists" to reject an existing target or mode="replace" to
drop and recreate it in one transaction. Query the current contents through
session.table("public.dt_orders").
Request Serverless Computing for a query by marking the DataFrame before its action:
rows = (
session.table("public.orders")
.filter(hg.col("amount") > 100)
.serverless(priority=4, required_cores=64, max_cores=128)
.collect()
)
The marker is lazy and immutable. At execution time the client applies
transaction-scoped SET LOCAL settings on the same connection as the query, so
they do not leak through the connection pool. Hologres still decides whether
the statement is eligible for Serverless execution; unsupported Serverless
settings raise an error instead of silently falling back.
Function Compute UDFs
FC account/region settings belong to the Session. Alibaba Cloud credentials come from the standard credential chain; do not put AK secrets in decorators:
session = hg.connect(
host="xxx.hologres.aliyuncs.com",
port=80,
dbname="my_db",
user="<access_id>",
password="<access_key>",
fc_config={
"endpoint": "123.cn-hangzhou-internal.fc.aliyuncs.com",
"region": "cn-hangzhou",
"role_arn": "acs:ram::123:role/fc-execution-role",
},
)
Decorators only validate and retain Python definitions. The first action using
the function packages its source/imports, creates or updates the FC function,
and registers LANGUAGE function_compute in Hologres. Later actions in the
same Session reuse the registration.
@hg.udf(packages=["numpy"])
def grade(n: int) -> str:
return "high" if n >= 2 else "low"
scored = session.table("public.scores").select("id", grade("score").alias("grade"))
UDTFs are called directly in select; no lateral-join API is required:
@hg.udtf(
output_schema=hg.StructType(
[
hg.StructField("word", hg.StringType()),
]
)
)
class SplitWords:
def process(self, text: str):
for word in text.split():
yield (word,)
words = session.table("public.docs").select("id", SplitWords("text"))
Hologres Remote UDX cannot return PostgreSQL record, so output_schema must
contain exactly one field. FC endpoints must be internal endpoints in the same
region as Hologres. Third-party packages are installed as Linux wheels for
the selected runtime; package names without compatible wheels fail during
deployment instead of producing an incompatible ZIP.
Runnable Examples
The examples directory contains scripts that connect directly to Hologres and exercise the implemented APIs:
- basic_query.py: filter, derive, project, and sort.
- join_and_aggregate.py: join and grouped aggregation inside Hologres.
- write_rows.py: append or UPSERT in-memory records into an existing table.
- oss_files.py: read and export OSS files through
EXTERNAL_FILES. - dynamic_table.py: create and refresh a Dynamic Table.
Connection values and example table names come from environment variables; see examples/README.md for the required schemas and commands.
Data types
Types are named after Snowpark/Spark and each knows the PostgreSQL type it compiles to:
| Python API | PostgreSQL |
|---|---|
BooleanType() |
boolean |
ByteType() |
"char" (1 byte; character semantics, needs ::int4 for arithmetic) |
ShortType() / IntegerType() / LongType() |
smallint / integer / bigint |
FloatType() / DoubleType() |
real / double precision |
DecimalType(38, 2) |
numeric(38,2) |
StringType() / StringType(64) |
text / varchar(64) |
BinaryType() |
bytea |
DateType() / TimeType() |
date / time |
TimestampType() / TimestampType(TimestampTimeZone.TZ) |
timestamp / timestamptz |
JsonbType() |
jsonb |
GeographyType() / GeometryType() |
geography / geometry (PostGIS) |
ArrayType(StringType()) |
text[] |
VectorType(float, 768) |
vector(768) (pgvector) |
StructType([StructField("word", StringType())]) |
row shape, e.g. RETURNS TABLE (word text) |
StructType is a client-side row descriptor, not a column type. It is what
df.schema returns and what @hg.udtf(output_schema=...) and
session.read_files(schema=...) accept.
Packaging
This distribution is named hologres-dataframe and installs into the
hologres namespace as hologres.dataframe, alongside hologres-client
(../holo-client-py), which it depends on for high-throughput write channels.
Implementation status
| Step | Scope | Done |
|---|---|---|
| C1 | Project scaffolding, data types, Row, exceptions |
✅ |
| C2 | Column expressions: col/lit, operators, alias/asc/desc |
✅ |
| C3 | Logical plan + PostgreSQL SQL generator | ✅ |
| C4 | Transformations: select/filter/sort/limit/... |
✅ |
| C5 | Session, hg.connect, actions, df.schema/df.columns |
✅ |
| C6 | group_by/agg, aggregate functions, hg.function/hg.expr |
✅ |
| C7a | join (USING/ON forms, relation-qualified columns) |
✅ |
| C7b | union/union_all, explode |
✅ |
| C8 | Catalog: use_schema/use_database, current_*, list_* |
✅ |
| C9a | from_dict/from_records (inline VALUES), object_table |
✅ |
| C9b | from_pandas (stage / scratch-table materialization) |
✅ |
| C9c | read_files for local csv/json/parquet |
✅ |
| C10 | df.write: SQL append/upsert, native overwrite + legacy fallback |
✅ |
| C11 | read_files/write_files (OSS EXTERNAL_FILES) |
✅ |
| C12 | AI functions (hg.ai.*) |
✅ |
| C13 | Vector search: distance methods, search_vector |
|
| C14 | Dynamic Table (as_dynamic_table, refresh_table) |
✅ |
| C15 | @hg.udf / @hg.udtf (Function Compute remote UDF) |
✅ |
| C16 | df.apply_agent (Holo Agent bridge) |
|
| C17 | Runnable Hologres examples | ✅ |
| C19 | DataFrame Serverless execution (df.serverless(...)) |
✅ |
Tests
python3 -m pytest # line coverage gate of 80% is enforced via pytest.ini
Tests do not need a live Hologres instance: the compiler is a pure plan-to-SQL function and is verified by asserting on generated SQL, while the execution layer is covered with fake connections.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hologres_dataframe-0.1.0.dev0.tar.gz.
File metadata
- Download URL: hologres_dataframe-0.1.0.dev0.tar.gz
- Upload date:
- Size: 170.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
878cbde850dce71a80ee0169e3b43fa472956edb6829096c5e6fc7a081167d6e
|
|
| MD5 |
b8a6795a7d308bd65d22270e389695c3
|
|
| BLAKE2b-256 |
714efe729cdb1f92a85ef6d029da84d771da8a7572ab8e9b3d719e21c7c74632
|
File details
Details for the file hologres_dataframe-0.1.0.dev0-py3-none-any.whl.
File metadata
- Download URL: hologres_dataframe-0.1.0.dev0-py3-none-any.whl
- Upload date:
- Size: 116.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa43a4172a96958e61d7982f2dfcdf4cecc62fe5b9b4e64728a8c365044a9bc
|
|
| MD5 |
539b91a79fa3b97e75e091d9b22aa438
|
|
| BLAKE2b-256 |
ef5ea2534ac01c0b3f0e76735403dbaf206830a76b80e54789691b18e0c1fa33
|