read_hive#
- ray.data.read_hive(table: str | None = None, *, connection_factory: Callable[[], Any], query: str | None = None, schema: pyarrow.Schema | None = None, user: str | None = None, limit: int | None = None, num_cpus: float | None = None, memory: float | None = None, resources: Dict[str, float] | None = None, label_selector: Dict[str, str] | None = None, fallback_strategy: List[Dict[str, Any]] | None = None, runtime_env: Dict[str, Any] | None = None, override_num_blocks: int | None = None) Dataset[source]#
Read a HiveServer2 table or trusted SQL query into a Dataset.
Install the optional
impylapackage on the driver and Ray workers. Configure authentication, transport, and TLS certificate verification inconnection_factory.GSSAPIalso requiresimpyla[kerberos]and Kerberos credentials on those nodes. The real-server integration test coversPLAINwith HiveServer2 in server modeNONE. It doesn’t coverNOSASLorGSSAPI.Note
Query reads require an explicit Arrow schema. DataSourceV2 planning needs it on the driver before the read worker executes the query. See issue #66840 for optional schema inference from the same query execution. Table reads select every column. If a table has unsupported column types, use
queryto select supported columns and provide a matching schema.Each Dataset execution runs at most one HiveServer2 data query in one Ray task. Ray doesn’t retry failed reads. With the default error tolerance, a read error or worker loss fails that Dataset execution. This API preserves
DataContext.max_errored_blocks. If you allow block errors, execution can skip failed output and return an incomplete result. This scanner doesn’t push Dataset filters, projections, orDataset.limit()into HiveServer2. Thelimitargument adds a SQLLIMITfor table reads. The HiveServer2 reader ignoresoverride_num_blockswith a warning to preserve streaming. Output blocks follow Ray’s normal block-sizing policy. This parameter doesn’t parallelize the HiveServer2 query.The reader attempts to cancel the HiveServer2 operation and close its cursor and connection when reading ends. Closing a Dataset iterator can force Ray to stop the read worker before Python cleanup runs. Immediate operation cancellation or explicit connection cleanup isn’t guaranteed.
Examples
Read a table or a query result. These examples assume
analytics.eventshas exactly two columns,id BIGINTandname STRING, in that order. TheSELECT *example assumes HiveServer2 returnsevents.idandevents.nameas result labels. Match the labels returned by your HiveServer2 instance.import os import pyarrow as pa import ray def create_connection(): from impala.dbapi import connect return connect( host="hive.example.com", port=10000, auth_mechanism="PLAIN", user="reader", password=os.environ["HIVE_NONE_PLACEHOLDER"], retries=1, ) table_ds = ray.data.read_hive( "analytics.events", connection_factory=create_connection ) query_ds = ray.data.read_hive( query="SELECT * FROM analytics.events", schema=pa.schema( [("events.id", pa.int64()), ("events.name", pa.string())] ), connection_factory=create_connection, ) # Use explicit SQL aliases to choose unqualified result labels. aliased_query_ds = ray.data.read_hive( query=( "SELECT id AS event_id, name AS event_name " "FROM analytics.events" ), schema=pa.schema( [("event_id", pa.int64()), ("event_name", pa.string())] ), connection_factory=create_connection, )
- Parameters:
table (str | None) – The Hive table to read, optionally qualified as
database.table. Specify exactly one oftableandquery.connection_factory (Callable[[], Any]) – A serializable function that takes no arguments and returns a new Impyla HiveServer2 connection on each call. Ray calls it on the driver for table metadata and on the read worker for data. Query reads with an explicit schema only call it on the read worker. Ray closes each returned connection. Configure authentication, TLS verification, and client retries in the factory. Read credentials inside the factory to avoid capturing them in its serialized state. Dependencies, credentials, and certificate files must be available wherever the factory runs.
query (str | None) – A trusted, row-producing SQL query. Specify exactly one of
tableandquery. The query is sent to HiveServer2 as given and must return a result set.schema (pyarrow.Schema | None) – The Arrow schema for a query read. Column names must match the HiveServer2 result labels, case-insensitively and in order. Hive may prefix
SELECT *result labels with the table name or alias. Use those labels in the schema or alias the columns in your query. Table reads infer their schema from HiveServer2 metadata;schemais only supported for query reads. Field types must use a supported Arrow mapping. HiveTIMESTAMPmaps topa.timestamp("us")without a time zone; sub-microsecond precision is truncated.user (str | None) – The HiveServer2 session user or proxy user passed to
connection.cursor(user=user). If omitted, Impyla uses the operating system username. Configure the authentication user separately inconnection_factory.limit (int | None) – The maximum number of rows to read from a table.
0skips the data query. The limit is sent to HiveServer2 as SQL. This argument isn’t supported for query reads.num_cpus (float | None) – The number of CPUs to reserve for the read task.
memory (float | None) – The heap memory in bytes to reserve for the read task.
resources (Dict[str, float] | None) – Custom resources to reserve for the read task, expressed as a mapping from resource name to quantity.
label_selector (Dict[str, str] | None) – Labels required on the node where the read task runs.
fallback_strategy (List[Dict[str, Any]] | None) – Alternative label requirements that Ray tries in order if
label_selectorcan’t be satisfied.runtime_env (Dict[str, Any] | None) – The runtime environment to use for the read task.
override_num_blocks (int | None) – An output block-count hint. The HiveServer2 reader ignores this hint and logs a warning when you supply a value. Output blocks follow Ray’s normal block-sizing policy. This parameter doesn’t add HiveServer2 query parallelism.
- Returns:
A
Datasetcontaining the HiveServer2 read result.- Return type:
PublicAPI (alpha): This API is in alpha and may change before becoming stable.