Skip to content

Four divergences between the embedded and remote TimeSeries schema paths, including a quote() that ignores the backslash and re-introduces #5849 #7740

Closed

Description

@ruispereira

Summary

Four issues in the remote TimeSeries schema surface added by edc38033ea (#7399) and 2ed4dcbe17 (#7335). They are grouped because they share one cause: the remote path renders SQL where the embedded path calls the API, and the two are meant to be equivalent. Each is small on its own; the first is the one that matters.


1. quote() refuses a back-quote and ignores the backslash, re-introducing #5849

/**
 * Back-quotes an identifier so a name that collides with a keyword still parses. A name that itself contains a
 * back-quote is refused: there is no escape for it in the grammar, and silently concatenating it would let a
 * caller-supplied name close the quote and continue the statement.
 */
private static String quote(final String identifier) {
  if (identifier.indexOf('`') >= 0)
    throw new SchemaException("Identifier '" + identifier + "' cannot be used in SQL: it contains a back-quote");
  return "`" + identifier + "`";
}

"There is no escape for it in the grammar" is not correct. SQLLexer.g4:511-517 is

QUOTED_IDENTIFIER : BACKTICK ( ~[`\\] | '\\' . )+ BACKTICK

A backslash escapes the next character. Identifier.quote() in the same module exists precisely to escape both characters, and this project already fixed this exact defect once, in MCPToolUtils.quoteIdentifier() under #5849, where the javadoc spells the lexer rule out.

Consequence on the remote path: buildTimeSeriesType().withName("a\\b")...create() renders `a\b`, the server parses the backslash as an escape and stores the type as ab, and create() then fails with "Type with name 'a\b' was not found" while the server keeps a fully built type under a name the caller never asked for. A trailing backslash gives a parse error instead. The embedded path accepts both names.

  • engine/src/main/java/com/arcadedb/schema/TimeSeriesTypeBuilder.java:267-276
  • call sites :202, :204, :234, :246
  • reached from network/src/main/java/com/arcadedb/remote/RemoteTimeSeriesTypeBuilder.java:60 and :72

Fix: use Identifier.quote(), or reproduce its escaping, rather than refusing one character and passing the other through.


2. Column order diverges between embedded and remote

renderCreate() has to regroup columns into TIMESTAMP, then TAGS, then FIELDS, because the grammar has one slot for each. The embedded create() replays insertion order:

for (final ColumnDefinition col : columns) type.addTsColumn(col);

A recipe declaring a field before the timestamp gives [cpu, ts, host] embedded and [ts, host, cpu] remotely.

  • TimeSeriesTypeBuilder.java:204-215 and :229-239 (the regrouping), :353-354 (the embedded order)
  • server side: engine/src/main/java/com/arcadedb/query/sql/parser/CreateTimeSeriesTypeStatement.java:79-91

This is the third instance of a divergence the same commit normalized twice elsewhere (the precision case, the tier sort). The #7399 acceptance IT declares columns in canonical order, so it cannot see it.

Fix: sort the columns into canonical order on the embedded path too, or document the order as unspecified and stop relying on it.


3. RemoteSchema.reload() keeps a cached type's Java class

RemoteDocumentType type = previous != null ? previous.get(typeName) : null;

The kind switch, including the LocalTimeSeriesType.KIND_CODE arm this commit added, runs only when the name is absent from the previous snapshot. So after a drop-and-recreate that changes a type's kind, even an explicit reload() leaves getType(name) instanceof TimeSeriesType false forever on that connection.

  • network/src/main/java/com/arcadedb/remote/RemoteSchema.java:829-860

Pre-existing line, made consequential by edc38033ea, since before it there was no kind for a remote type to change into.

Fix: re-run the kind switch on reload, and reuse the cached instance only when the kind matches.


4. validate() does not enforce the single-TIMESTAMP rule that validateForSQL() does

if (timestampColumns > 1)
  throw new SchemaException(
      "CREATE TIMESERIES TYPE declares exactly one TIMESTAMP column, and this builder carries " + timestampColumns);

That check is in validateForSQL() only. validate(), which the embedded create() runs, does not have it. JsonlImporterFormat loops withColumn over export JSON, so a two-TIMESTAMP export builds a type whose getTimestampColumn() (the last) disagrees with findTimestampColumnIndex() (the first).

  • TimeSeriesTypeBuilder.java:282-307 (validate()), :311-324 (validateForSQL()), :130-136 (withColumn)
  • integration/src/main/java/com/arcadedb/integration/importer/format/JsonlImporterFormat.java:475-494
  • engine/src/main/java/com/arcadedb/engine/timeseries/TimeSeriesSealedStore.java:3307-3312

Fix: move the check into validate(), so the rule holds wherever the type is created. That is what validate()'s own javadoc says it is for.

Scope / confidence

Item 1: high confidence, the lexer rule was read in the grammar file at 151799eda2. It stops short of full SQL injection, because the back-quote half of the guard does block re-balancing the quoting, which is why it is not filed as high severity.

Items 2, 3 and 4: high confidence on the mechanism, low individual impact.

Not included here: the partial-construction case where CREATE succeeds and a follow-up ALTER fails, which is real but already owned by #7689. #7335's SQL suggestions were checked against the grammar and are all current productions.

Activity

  1. added
    engine
    network
    timeseries
    on Sep 16, 2026
  2. added this to the 26.10.1 milestone on Sep 16, 2026
  3. added
    in progress
    on Sep 16, 2026
  4. self-assigned this
    on Sep 16, 2026
  5. added 2 commits that reference this issue on Sep 17, 2026
  6. lvca commented on Sep 17, 2026

    @lvca
    Member

    Fixed in #7747, merged into main for 26.10.1. All four items:

    1. Identifier escaping. A type or column name containing a backslash was silently altered - a\b became ab on the server, and create() then failed saying the type was not found while the server kept one under a name you never asked for. A trailing backslash was a parse error. Both now work: names are escaped with the same routine the rest of the SQL layer uses, and the injection the old check was guarding against is still refused.
    2. Column order. The order you declare columns in is now kept as given when creating a type in the embedded API - it is part of the type, since samples are written positionally. CREATE TIMESERIES TYPE can only spell timestamp, then tags, then fields, so a recipe that interleaves them renders in that grouped order; the JSONL importer refuses a restore if the type it rebuilt does not match the export's own column order, rather than importing values into the wrong columns.
    3. Remote schema cache. Dropping a type and recreating it as a different kind - for example a document type recreated as a time-series type - left an open remote connection answering with the old kind forever, even after an explicit reload(). It now picks up the change.
    4. Two timestamp columns. A type declaring more than one TIMESTAMP column is refused when creating it embedded, as it already was over SQL, instead of producing a type whose reads disagree with each other.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 17, 2026
  8. added 2 commits that reference this issue on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginenetworksqltimeseries

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions