Repository navigation
Conversation
Signed-off-by: jiangxt2 <[email protected]>
Signed-off-by: jiangxt2 <[email protected]>
|
I think this looks fine; thanks. |
OK, I will submit an implementation PR soon. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new HiveServer2 read API contract, defining HiveConnectionOptions and HiveReadSpec dataclasses to handle input validation for table and query reads. It also includes comprehensive unit tests and a new Bazel build target for these components. The reviewer suggested a minor optimization to the identifier regex pattern by removing the redundant \Z anchor, as re.fullmatch already enforces a full string match.
|
|
||
| HiveAuthMechanism = Literal["NOSASL", "PLAIN", "GSSAPI"] | ||
|
|
||
| _IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*\Z") |
There was a problem hiding this comment.
The \Z anchor in the regular expression is redundant because re.fullmatch is used to validate the identifier segments. re.fullmatch inherently requires the entire string to match the pattern. Removing \Z simplifies the regex pattern.
| _IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*\Z") | |
| _IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*") |
There was a problem hiding this comment.
You’re right that \Z is redundant with re.fullmatch(). Since it has no behavioral impact, I’ll leave it unchanged in this PR.
|
|
||
| This module defines the API boundary without opening a Hive connection or | ||
| creating a Ray read task. The public call shape is specified separately in the | ||
| read_hive API contract proposal. |
There was a problem hiding this comment.
This module says the public call shape is "specified separately", and right now that means the PR description. The thing we need to align on is the read_hive() signature and its semantics, and a later PR can change those freely because nothing here is imported or exported.
Could you put the contract in the code so approving this PR locks it? A stub in read_api.py with the full signature and docstring that raises NotImplementedError would do. Then this module can be reviewed as the validation layer behind that signature instead of standing alone.
| auth_mechanism: HiveAuthMechanism | ||
| port: int = 10000 | ||
| user: Optional[str] = None | ||
| password: Optional[str] = field(default=None, repr=False) |
There was a problem hiding this comment.
repr=False hides the password from repr, but it is not a security boundary. This dataclass gets pickled into the read task and into Dataset.serialize_lineage(), and a password= kwarg on read_hive() ends up in notebooks and job specs.
It also means nine connection parameters on the public function, and the PR already lists LDAP, HTTP transport and Impyla passthrough as follow-ups, so the signature will keep growing.
Existing readers avoid both problems: read_sql takes a connection_factory, read_snowflake a connection_parameters dict, read_databricks_tables reads a token from the environment. Impyla's connect is already a callable the user can configure. Can read_hive take a connection_factory (or a single public options object) and drop password from the public API?
| ): | ||
| raise ValueError("query must be a non-empty SQL string") | ||
| if not isinstance(self.schema, pa.Schema) or len(self.schema) == 0: | ||
| raise ValueError("query reads require a non-empty pyarrow.Schema") |
There was a problem hiding this comment.
HiveServer2 returns result metadata after execute and before any row is fetched, and impyla exposes it as cursor.description. That already satisfies the "no second data query" rule.
Requiring every SQL user to hand-write a pyarrow.Schema is a real usability cost for something the server can tell us. Can schema be optional for query reads, inferred from the cursor description, and used as an override when given?
|
|
||
| @dataclass(frozen=True) | ||
| class HiveReadSpec: | ||
| """A single table or trusted SQL read, before datasource execution.""" |
There was a problem hiding this comment.
The one-query, one-task, no-retry model is a clear and safe choice for the first version. Two consequences are worth stating in the public docs so users aren't surprised: reads won't run in parallel, and if the worker running the query is lost the whole dataset fails, since Ray can't re-run that task.
With those semantics the read path looks close to read_sql(sql, impyla_connect) plus a table-name helper and Arrow type mapping. Could you add a short note on what read_hive provides beyond that today? If the main gains are the Arrow typing from HS2 metadata and incremental fetching, it might be worth a quick discussion on whether some of that could strengthen read_sql as well. Not a blocker for the direction, just want the distinction written down.
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class HiveReadSpec: |
There was a problem hiding this comment.
One thing I'd love to see covered here, since DataSourceV2 alignment came up early in the RFC: a short note on how this spec maps onto the DataSourceV2 interfaces. For example, one input split per query, schema coming from HS2 metadata through the metadata interface, streaming happening inside the scanner, and how cancellation and cleanup fit in.
It doesn't need to be code yet, a paragraph here or in the PR body is enough. It's the trickiest part of the integration, so agreeing on it now should make the implementation PR much smoother to review.
|
Hey @jiangxt2! Thanks for splitting the contract out ahead of the implementation, this is exactly the right order and it makes the review much easier. I left five inline comments that touch the public API shape: putting the read_hive signature itself in code, using a connection factory instead of flat connection kwargs and a password argument, making schema optional for query reads, spelling out the single-task semantics and how they compare with read_sql, and sketching the DataSourceV2 mapping. I think it's worth settling those before we treat this as the agreed contract, since they're the parts a follow-up PR can't easily change. The remaining code-level points are small and can come along in the same push. Happy to discuss any of them here or on the RFC thread. |
|
PR #66523 was opened to define and validate the proposed |
Description
This PR defines the proposed alpha
ray.data.read_hive()API contract requested in RFC #65978. It adds validated, immutable input models and focused tests so maintainers can align on the API before reviewing the HiveServer2 reader.The public
read_hivesymbol shown below is proposed for a follow-up implementation PR. This PR does not export it, connect to Hive, or read data.Proposed public API
Decisions for review
tableandqueryis required. Table names use the initial simple[database.]tableidentifier subset. Each identifier segment must match ASCII[A-Za-z_][A-Za-z0-9_]*; an unqualified name usesdefault. Table reads get their Arrow schema from HS2 metadata during planning. If that metadata cannot fully describe the result, planning fails instead of running an extra data query to infer the schema. A tablelimit=0skips the data query.pyarrow.Schemawith column names unique after case folding. HS2 result columns must have the same count and order, with names matching case-insensitively. Output keeps the caller's schema names. Unsupported or lossy type mappings fail before emitting a block; non-nullable fields are checked against fetched rows. Schema inference must not execute the data query a second time.auth_mechanismis required. The initial binary HS2 profiles areNOSASLfor a Hive server configured asNOSASL,PLAINfor HiveNONE, andGSSAPIfor HiveKERBEROS.PLAINrequires an explicit nonempty user and password in this API. For HiveNONE, use a non-sensitive placeholder password: the server does not authenticate it, and PLAIN does not encrypt it without TLS. TLS must verify the server certificate and identity. When set,timeoutconfigures the HS2 transport socket timeout in seconds; it is not a server-side or end-to-end query deadline.max_retries=0) and verify that failures cannot resubmit it. Sourcelimitapplies only to table reads; query SQL is not rewritten for pushdown.override_num_blocksdoes not create parallel HS2 queries. Parallelism, concurrency, retry, GPU/accelerator placement, and Impyla passthrough arguments are outside the initial public API.write_hiveremain follow-up work.Related issues
Related to #65978.
Additional information
Scope and prior work
This PR changes only
hive_contract.py, its validation tests, and the Bazel test registration. It does not duplicate an openread_hivePR: searches for #65978 andread_hivefound none. Closed, unmerged PR #58253 explored direct storage reads; this PR defines the HS2-first API boundary and leaves direct reads for later.Validation
pytestrun ofpython/ray/data/tests/datasource/test_hive_contract.pyin an isolated Python 3.13 environment, using the PR branch's Ray Data Python sources with a locally built Ray extension: 34 passed.pre-commit run --files python/ray/data/BUILD.bazel python/ray/data/_internal/datasource/hive_contract.py python/ray/data/tests/datasource/test_hive_contract.py: passed.git diff --check origin/master...HEADand Ruff: passed.AI assistance
AI assistance was used for research, the contract model, tests, and this PR description. Before requesting review, the human submitter must review every changed line and rerun the relevant tests locally.