-
Notifications
You must be signed in to change notification settings - Fork 947
TIKA-4766: typed Document parse contract for tika-grpc #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krickert
wants to merge
1
commit into
apache:main
Choose a base branch
from
ai-pipestream:TIKA-4766-document-contract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Apache Tika gRPC API | ||
|
|
||
| Typed protobuf messages for Tika parse output under `org.apache.tika.grpc.v1`. | ||
|
|
||
| ## Contents | ||
|
|
||
| - **Document** (`document.proto`) — the single, small, stable parse-result contract: a | ||
| structured markdown content tree (`blocks`/`markdown`), typed common metadata | ||
| (`DocumentMetadata`), and a tagged metadata tail (`extra`) for everything | ||
| format-specific. | ||
| - **Bundled descriptors** — `META-INF/org.apache.tika.grpc.v1.descriptors` in the | ||
| published jar. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```xml | ||
| <dependency> | ||
| <groupId>org.apache.tika</groupId> | ||
| <artifactId>tika-grpc-api</artifactId> | ||
| <version>${tika.version}</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| ## The Document shape | ||
|
|
||
| Rather than one proto message per source format, `Document` models content and | ||
| metadata by *concern*, not by *format*: | ||
|
|
||
| - **Content** lives in `markdown` (the authoritative render) and `blocks` (the same | ||
| content parsed into a structured tree of headings/paragraphs/lists/tables/code | ||
| blocks/inline runs). This is format-agnostic: every Tika parser's output reaches | ||
| this shape the same way, via markdown. | ||
| - **Metadata** has a small, bounded set of typed common fields on `DocumentMetadata` | ||
| (title, authors, description, keywords, languages, dates, counts, dimensions, | ||
| rights) plus a tagged tail (`extra`, a `repeated MetadataField`) for everything | ||
| format-specific. Tail values are typed where Tika's own `Property` declares a type | ||
| (integer/number/boolean/timestamp), and a string otherwise — never guessed. | ||
| - **`format_category`** is a cheap routing hint (`FormatCategory` enum: PDF, OFFICE, | ||
| IMAGE, HTML, RTF, EPUB, WARC, GENERIC). It is not mutually exclusive with anything | ||
| in `extra` — a document can be `FORMAT_CATEGORY_PDF` and still carry Creative | ||
| Commons rights metadata, for example. | ||
| - **`embedded`** recurses: a PDF with an embedded image is one `Document` whose | ||
| `embedded` list contains a fully-typed child `Document` for the image. | ||
|
|
||
| Format-specific mapping (which Tika `Property` becomes which typed field, and what | ||
| falls through to `extra`) lives in `tika-grpc-mapper`'s | ||
| `org.apache.tika.grpc.mapper.transform.DocumentTransformer` implementations, one per | ||
| format — code, not schema. Adding a parser means adding a transformer; the wire | ||
| contract does not change. | ||
|
|
||
| ## Lint | ||
|
|
||
| ```bash | ||
| cd tika-grpc-api && buf lint | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # 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. | ||
|
|
||
| version: v2 | ||
| modules: | ||
| - path: src/main/proto | ||
| name: buf.build/apache/tika-grpc-api | ||
| deps: | ||
| - buf.build/googleapis/googleapis | ||
| lint: | ||
| use: | ||
| - STANDARD | ||
| breaking: | ||
| use: | ||
| - FILE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>tika-grpc-api</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>Apache Tika gRPC API (typed Document protos)</name> | ||
| <url>https://tika.apache.org/</url> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.tika</groupId> | ||
| <artifactId>tika-parent</artifactId> | ||
| <version>${revision}</version> | ||
| <relativePath>../tika-parent/pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.protobuf</groupId> | ||
| <artifactId>protobuf-java</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <extensions> | ||
| <extension> | ||
| <groupId>kr.motd.maven</groupId> | ||
| <artifactId>os-maven-plugin</artifactId> | ||
| <version>1.7.1</version> | ||
| </extension> | ||
| </extensions> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.xolstice.maven.plugins</groupId> | ||
| <artifactId>protobuf-maven-plugin</artifactId> | ||
| <version>0.6.1</version> | ||
| <configuration> | ||
| <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact> | ||
| <protoSourceRoot>${project.basedir}/src/main/proto</protoSourceRoot> | ||
| <includes> | ||
| <include>org/apache/tika/grpc/v1/*.proto</include> | ||
| </includes> | ||
| <writeDescriptorSet>true</writeDescriptorSet> | ||
| <includeDependenciesInDescriptorSet>true</includeDependenciesInDescriptorSet> | ||
| <descriptorSetOutputDirectory>${project.build.outputDirectory}/META-INF</descriptorSetOutputDirectory> | ||
| <descriptorSetFileName>org.apache.tika.grpc.v1.descriptors</descriptorSetFileName> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>compile</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>build-helper-maven-plugin</artifactId> | ||
| <version>3.6.1</version> | ||
| <executions> | ||
| <execution> | ||
| <id>add-protobuf-sources</id> | ||
| <phase>generate-sources</phase> | ||
| <goals> | ||
| <goal>add-source</goal> | ||
| </goals> | ||
| <configuration> | ||
| <sources> | ||
| <source>${project.build.directory}/generated-sources/protobuf/java</source> | ||
| </sources> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifestEntries> | ||
| <Automatic-Module-Name>org.apache.tika.grpc.api</Automatic-Module-Name> | ||
| </manifestEntries> | ||
| </archive> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-checkstyle-plugin</artifactId> | ||
| <configuration> | ||
| <excludeGeneratedSources>true</excludeGeneratedSources> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.rat</groupId> | ||
| <artifactId>apache-rat-plugin</artifactId> | ||
| <configuration> | ||
| <inputExcludes> | ||
| <inputExclude>README.md</inputExclude> | ||
| </inputExcludes> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only change anywhere in
tika-e2e-tests/tika-grpcfor this PR (this line and the analogous one at line 334 for the TEXT handler). It's a compile-fix that keeps the pre-existing "content is non-empty" assertion alive against the new API, but it does not exercise the new typed contract through the live gRPC server at all.None of the e2e tests (
HandlerTypeTest,FileSystemFetcherTest,IgniteConfigStoreTest,ExternalTestBase) assert on:document.metadata(typed title/authors/dates/counts)document.extra(tagged-tail typing: int/bool/date/string)document.blocks(structured content tree: headings/tables/lists/code)document.embedded(recursion for container formats, e.g. an Office doc with an embedded image)document.format_categoryFileSystemFetcherTest/IgniteConfigStoreTest/ExternalTestBaseonly ever inspectgetFetchKey()/getStatus()onFetchAndParseReplyand never callgetDocument()at all, so the bulk-corpus/streaming/ignite e2e paths give zero signal on the new contract this PR introduces.The real proof of correctness lives entirely in
tika-grpc-mapper's unit tests, which feed fixture-derivedMetadata/markdown intoDocumentBuilderin-process -- good for the mapping logic, but it bypasses the actual gRPC wire serialization, the live server (TikaGrpcServerImpl), the pipes client, and fetcher plumbing entirely.Requesting: add (or extend this test) at least one e2e case per format that fetches a real file through the live server and asserts on a couple of
document.metadatafields, at least onedocument.extratagged key, and onedocument.embeddedcase -- not just thatmarkdownis non-empty.