Skip to content

improve DX for type inference and format detection - #7531

Merged
mccanne merged 1 commit into
mainfrom
anyio-source
Oct 26, 2026
Merged

mccanne merged 1 commit into
mainfrom
anyio-source

Conversation

@mccanne

@mccanne mccanne commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

This commit further improves upon the recent changes to auto-detection and type inference. Two problems were apparent with the previous approach: "from http://... | ..." failed with unknown format and "super -static -i auto -c '...' -" failed with cannot get type of non-seekable.

This commit solves these problems by reading the inputs into memory (and reusing the memory buffering across type inference and query scan). The buffering occurs in a new entity anyio.Source and a sources table maps URIs of inputs to a Source.

-static now forces the input to be read and buffered when the input doesn't have native type support.

In the future, we will have better HTTP support for range requests and we can devise a better approach for type and format inference for HTTP. For now, reading the whole body has nice DX at the cost of bad perf for large and otherwise seekable HTTP endpoints.

// FileType returns the fused type of the input at path or nil if the input
// is dynamically typed. See anyio.Source.Type.
func (e *Environment) FileType(ctx context.Context, sctx *super.Context, path, format string) (super.Type, error) {
if e.Dynamic || e.sources == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check for e.Stdin!=nil.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed...

This commit further improves upon the recent changes to
auto-detection and type inference.  Two problems were
apparent with the previous approach: "from http://... | ..."
failed with unknown format and "super -static -i auto -c '...' -"
failed with cannot get type of non-seekable.

This commit solves these problems by reading the inputs
into memory (and reusing the memory buffering across type
inference and query scan).  The buffering occurs in a new
entity anyio.Source and a sources table maps URIs of inputs
to a Source.

-static now forces the input to be read and buffered when
the input doesn't have native type support.

In the future, we will have better HTTP support for range
requests and we can devise a better approach for type and
format inference for HTTP.  For now, reading the whole body
has nice DX at the cost of bad perf for large and otherwise
seekable HTTP endpoints.
@mccanne
mccanne merged commit 2541475 into main Oct 26, 2026
6 checks passed
@mccanne
mccanne deleted the anyio-source branch October 26, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants