Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions core/src/main/java/org/apache/datafusion/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# Public API

These instructions apply to the public Java API in this package and its subpackages.

The public Java API mirrors the upstream Rust DataFusion API. Before adding a public type or method,
find its Rust counterpart and match it.

- Use the Rust type, trait, method, and enum names: `snake_case` becomes `camelCase`, and enum
variants become `SCREAMING_SNAKE_CASE` (`JoinType::LeftSemi` becomes `JoinType.LEFT_SEMI`).
- Don't invent a Java-only name or type when Rust already has one.
- Rust traits map to Java interfaces. Optional trait methods are `default` methods.
- Rust enums whose variants carry no data become Java `enum`s. Rust enums where any variant
carries data become a `sealed interface` named after the enum, with one nested `record` per
variant, named like the Rust variant in PascalCase (`Partitioning::Hash(exprs, n)` becomes
`record Hash(List<Expr> exprs, int n)` implementing `Partitioning`, as `ColumnarValue` does).
Variants with no data become records with no components, not singleton constants.
- Rust structs whose fields are all `pub` and that are plain data become `record`s
(`ScalarFunctionArgs`). Structs with private fields and `new()`/`with_*` setters become final
classes with builders, since adding a record component breaks callers.
- If the Rust enum is `#[non_exhaustive]`, say so in the Javadoc: new variants may be added, so
callers should include a `default` case when they `switch` over it.
- Covering only part of a Rust API is fine. When you leave something out, note the gap rather than
reshaping the API around it.
- Java-only additions are OK when they're needed for Java idioms (varargs, `Optional`). Say in the
Javadoc that the addition is Java-specific.
- Each public type's Javadoc names its Rust counterpart ("Mirrors DataFusion's {@code ScanArgs}").
A docs.rs link is welcome but not required.
- A Java method whose Rust counterpart returns `Result` throws the unchecked `DataFusionException`
subclass matching the `DataFusionError` variant (`PlanException`, `ExecutionException`, …). Don't
add checked exceptions.
- Never expose JNI details in public signatures: no native handles, no `byte[]` marshalling
payloads, no codes for crossing the JNI boundary. Keep helpers like `toBytes()` package-private.
- A type that holds a native handle (`SessionContext`, `DataFrame`) implements `AutoCloseable`, and
`close()` frees the native resource. Plain value types and Java-implemented interfaces don't.
20 changes: 20 additions & 0 deletions core/src/main/java/org/apache/datafusion/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

@AGENTS.md