vaticle / typedb

TypeDB: the polymorphic database powered by types
https://typedb.com
Mozilla Public License 2.0
3.72k stars 337 forks source link

Simple typeql rule definition leads to off-by-one out of index error #6350

Closed hmprt closed 3 years ago

hmprt commented 3 years ago

Please replace every line in curly brackets { like this } with an appropriate answer, and remove this line.

Description

{ Please provide a clear and concise description of the bug. }

Environment

  1. OS: MacOS
  2. TypeDB 2.1.1
  3. TypeDB client: console

Reproducible Steps

Load this schema using the source command in the TypeDB console.

# BEGIN SCHEMA DEFINITION
define

# ATTRIBUTES - fundamental attributes to describe meta-types. Employed by multiple classes.

## Textual attributes:
TEXT sub attribute, value string;

## Content attributes:
SOURCE sub attribute, value string;
URL sub attribute, value string;
TITLE sub attribute, value string;
CONTENT_TYPE sub attribute, value string;

## Index attributes:
TEXT_INDEX sub attribute, value long;
START_INDEX sub attribute, value long;
END_INDEX sub attribute, value long;

## Cryptography attributes
MD5_HASH sub attribute, value string;

# RELATIONS - fundamental relations between meta-types

##CONTAINING -  i.e documents CONTAIN sentences CONTAIN tokens
CONTAINING sub relation,
        relates CONTAINER,
        relates CONTAINED;

### MENTIONING - i.e entites are MENTIONED in sentences etc
MENTIONING sub relation,
        relates MENTIONED,
        relates MENTIONED_BY;

# TYPES - core meta-types which reflect data structures in our ontology

### CORPUS - core type representing corpuses of textual content
CORPUS sub entity,
        owns TITLE,
        owns URL,
        owns SOURCE,
        owns CONTENT_TYPE,
        plays CONTAINING:CONTAINER;

### COMMUNICATION - core type representing textual content
COMMUNICATION sub entity,
        owns TEXT,
        owns MD5_HASH @key,
        owns TITLE,
        owns URL,
        owns CONTENT_TYPE,
        owns SOURCE,

        plays CONTAINING:CONTAINER,
        plays CONTAINING:CONTAINED;

Then load this schema using the source command in console

# BEGIN SCHEMA DEFINITION
define

## Container rule:
### If x contains y, and y contains z, x contains z.

rule inheritance-of-containment:
when {
(CONTAINER: $x, CONTAINING: $y) isa CONTAINING;
} then {
(CONTAINER: $x, CONTAINED: $z) isa CONTAINING;
}

Expected Output

Concepts have been defined

Actual Output

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 16 out of bounds for length 15
        at java.base/java.util.Arrays$ArrayList.get(Arrays.java:4372)
        at com.vaticle.typeql.lang.parser.ErrorListener.syntaxError(ErrorListener.java:69)
        at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
        at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:544)
        at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
        at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
        at com.vaticle.typeql.grammar.TypeQLParser.eof_queries(TypeQLParser.java:272)
        at com.vaticle.typeql.lang.parser.Parser.parse(Parser.java:141)
        at com.vaticle.typeql.lang.parser.Parser.parseQueriesEOF(Parser.java:156)
        at com.vaticle.typeql.lang.TypeQL.parseQueries(TypeQL.java:71)
        at com.vaticle.typedb.console.TypeDBConsole.runQuery(TypeDBConsole.java:421)
        at com.vaticle.typedb.console.TypeDBConsole.runSource(TypeDBConsole.java:411)
        at com.vaticle.typedb.console.TypeDBConsole.runTransactionRepl(TypeDBConsole.java:319)
        at com.vaticle.typedb.console.TypeDBConsole.runRepl(TypeDBConsole.java:275)
        at com.vaticle.typedb.console.TypeDBConsole.runInteractive(TypeDBConsole.java:230)
        at com.vaticle.typedb.console.TypeDBConsole.main(TypeDBConsole.java:492)

Additional information

None - this looks like a pretty straightforward bug

{ Any additional information, including logs or screenshots if you have any. }

hmprt commented 3 years ago

This was my bad - a faulty schema file!