influxdata / influxdata/influxdb

[InfluxDB 2.x] Import declaration not working when declared in `extern` JSON node

Open
#24,734 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

The `/api/v2/query` endpoint provides a way to specify import declaration as an AST JSON object (`ImportDeclaration`) in the `extern` node.
This declaration seems to be ignored when running the query.

__Step to reproduce:__
Call `POST /api/v2/query?org={{yourOrg}}` with the following body:
```json
{
"type": "flux",
"extern": {
"type": "file",
"imports": [
{
"type": "ImportDeclaration",
"as": null,
"path": {
"type": "StringLiteral",
"value": "array"
}
}
],
"body": []
},
"query": "array.from(rows: [{test: \"ok\"}])"
}
```

__Expected behaviour:__
The query executed with the imported `array` package considered.

__Actual behaviour:__
An HTTP 400 status code with the following body:
```json
{
"code": "invalid",
"message": "error @1:1-1:6: undefined identifier array"
}
```
It is also not working for any other package.

__Important notes:__
1. Specifying an alias for the package to be imported also does not work:
```json
{
"type": "ImportDeclaration",
"as": { "type": "Identifier", "name": "array" },
"path": { "type": "StringLiteral", "value": "array" }
}
```
2. Using the `POST /api/v2/query/ast?org={{yourOrg}}` endpoint helps to determine the right JSON notation for the AST node:
![Generated from the query](https://github.com/influxdata/influxdb/assets/22419043/b6ef54b9-ab34-4d8c-a235-e9480caee747)

__Environment info:__
* InfluxDB OSS v2.7.1 running on Windows 11 23H2 (build 22631.3235)
* Same issue on InfluxDB Cloud (powered by TSM) with Storage Engine Version 2 (167c4c6)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the POST /api/v2/query request with the supplied extern AST and compare it with the POST /api/v2/query/ast endpoint, which shows the JSON notation. Trace how the ImportDeclaration in extern is processed before query execution. Done means imported packages, including array and aliased imports, are recognized and the query no longer returns an undefined identifier error.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, rust
Domain
api, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.