Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 98 additions & 116 deletions engine/src/main/grammar/SQLGrammar.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2349,31 +2349,6 @@ SchemaIdentifier SchemaIdentifier():
{ return jjtThis; }
}

IndexName IndexName():
{
StringBuilder builder = new StringBuilder();
Token token;
Identifier lastIdentifier;
}
{
( "__@recordmap@___" { builder.append("__@recordmap@___"); } )?

lastIdentifier = Identifier() { builder.append(lastIdentifier.getValue()); }
(
(
<DOT> { builder.append("."); }
|
<MINUS> { builder.append("-"); }
)
lastIdentifier = Identifier() { builder.append(lastIdentifier.getValue()); }
)*
{
jjtThis.value = builder.toString();
return jjtThis;
}
}


IndexIdentifier IndexIdentifier():
{
Token token;
Expand All @@ -2382,7 +2357,7 @@ IndexIdentifier IndexIdentifier():
(
(
<INDEX_COLON>
jjtThis.indexName = IndexName() { jjtThis.type = IndexIdentifier.Type.INDEX; }
jjtThis.indexName = Identifier() { jjtThis.type = IndexIdentifier.Type.INDEX; }
)
|
(
Expand Down Expand Up @@ -3844,110 +3819,117 @@ CreateIndexStatement CreateIndexStatement():
}
{
<CREATE> <INDEX>
jjtThis.name = IndexName()
(
LOOKAHEAD(4)
[ <IF> <NOT> <EXISTS> {jjtThis.ifNotExists = true;} ]
<ON>
jjtThis.typeName = Identifier()
<LPAREN>
(
(
lastIdentifier = Identifier() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.name = lastIdentifier;
jjtThis.propertyList.add(lastProperty);
}
LOOKAHEAD(6)
(
[<IF> <NOT> <EXISTS> {jjtThis.ifNotExists = true;}]
<ON>
jjtThis.typeName = Identifier()
<LPAREN>
(
lastIdentifier = Identifier() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.name = lastIdentifier;
jjtThis.propertyList.add(lastProperty);
}
|
lastRecordAttr = RecordAttribute() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.recordAttribute = lastRecordAttr;
jjtThis.propertyList.add(lastProperty);
}
)
[
<BY>
(
<KEY> { lastProperty.byKey = true; }
|
<VALUE> { lastProperty.byValue = true; }
)
]
(
<COMMA>
(
lastIdentifier = Identifier() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.name = lastIdentifier;
jjtThis.propertyList.add(lastProperty);
}
|
lastRecordAttr = RecordAttribute() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.recordAttribute = lastRecordAttr;
jjtThis.propertyList.add(lastProperty);
}
)
[
<BY>
(
<KEY> { lastProperty.byKey = true; }
|
<VALUE> { lastProperty.byValue = true; }
)
]
)*
<RPAREN>
)
|
lastRecordAttr = RecordAttribute() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.recordAttribute = lastRecordAttr;
jjtThis.propertyList.add(lastProperty);
}
)
[
<BY>
(
<KEY> { lastProperty.byKey = true; }
|
<VALUE> { lastProperty.byValue = true; }
jjtThis.name = Identifier()
)
]
)
(
<COMMA>
(
lastIdentifier = Identifier() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.name = lastIdentifier;
jjtThis.propertyList.add(lastProperty);
}
LOOKAHEAD(4)
(
<IF> <NOT> <EXISTS> {jjtThis.ifNotExists = true;}
jjtThis.type = Identifier()
)
|
lastRecordAttr = RecordAttribute() {
lastProperty = new CreateIndexStatement.Property();
lastProperty.recordAttribute = lastRecordAttr;
jjtThis.propertyList.add(lastProperty);
}
)
jjtThis.type = Identifier()
)
(
LOOKAHEAD(2)
<ENGINE> jjtThis.engine = Identifier()
[
<BY>
LOOKAHEAD(2)
(
<KEY> { lastProperty.byKey = true; }
|
<VALUE> { lastProperty.byValue = true; }
<SCHEMA> jjtThis.schema = Json()
)
|
(
lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
(
<COMMA> lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
)*
[ <SCHEMA> jjtThis.schema = Json() ]
)
]
)*
<RPAREN>
jjtThis.type = Identifier()
|
(
LOOKAHEAD(3)
<IF> <NOT> <EXISTS> {jjtThis.ifNotExists = true;} jjtThis.type = Identifier()
|
jjtThis.type = Identifier()
)
)

(
LOOKAHEAD(2)
<ENGINE> jjtThis.engine = Identifier()
[
LOOKAHEAD(2)
(
<SCHEMA> jjtThis.schema = Json()
)
|
(
lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
[
LOOKAHEAD(2)
(
<COMMA> lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
)*
[ <SCHEMA> jjtThis.schema = Json() ]
)
]
|
[
LOOKAHEAD(2)
(
<SCHEMA> jjtThis.schema = Json()
)
|
(
lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
<SCHEMA> jjtThis.schema = Json()
)
|
(
<COMMA> lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
)*
[ <SCHEMA> jjtThis.schema = Json() ]
lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
(
<COMMA> lastIdentifier = Identifier() {jjtThis.keyTypes.add(lastIdentifier);}
)*
[ <SCHEMA> jjtThis.schema = Json() ]
)
]
)

[ <NULL_STRATEGY>
(
<SKIP2> { jjtThis.nullStrategy = LSMTreeIndexAbstract.NULL_STRATEGY.SKIP; }
|
<ERROR2> { jjtThis.nullStrategy = LSMTreeIndexAbstract.NULL_STRATEGY.ERROR; }
)
]
)
[ <NULL_STRATEGY>
(
<SKIP2> { jjtThis.nullStrategy = LSMTreeIndexAbstract.NULL_STRATEGY.SKIP; }
|
<ERROR2> { jjtThis.nullStrategy = LSMTreeIndexAbstract.NULL_STRATEGY.ERROR; }
)
]

{ return jjtThis; }
}

Expand All @@ -3956,7 +3938,7 @@ RebuildIndexStatement RebuildIndexStatement():
{
<REBUILD> <INDEX>
(
jjtThis.name = IndexName()
jjtThis.name = Identifier()
|
<STAR> { jjtThis.all = true; }
)
Expand All @@ -3968,7 +3950,7 @@ DropIndexStatement DropIndexStatement():
{
<DROP> <INDEX>
(
jjtThis.name = IndexName()
jjtThis.name = Identifier()
|
<STAR> { jjtThis.all = true; }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.arcadedb.query.sql;

import com.arcadedb.database.DatabaseInternal;
import com.arcadedb.query.QueryEngine;
import com.arcadedb.query .QueryEngine;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.query.sql.executor.SQLEngine;
import com.arcadedb.query.sql.parser.Limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class CreateIndexStatement extends DDLStatement {

protected IndexName name;
protected Identifier name;
protected Identifier typeName;
protected List<Property> propertyList = new ArrayList<Property>();
protected Identifier type;
Expand Down Expand Up @@ -85,11 +85,15 @@ else if (typeAsString.equalsIgnoreCase("NOTUNIQUE"))
Object execute(final CommandContext ctx) {
final Database database = ctx.getDatabase();

if (name == null)
// GENERATE THE NAME AUTOMATICALLY
name = new Identifier(typeName.getStringValue() + propertyList.toString());

if (database.getSchema().existsIndex(name.getValue())) {
if (ifNotExists) {
return null;
} else {
throw new CommandExecutionException("Index " + name + " already exists");
throw new CommandExecutionException("Index '" + name + "' already exists");
}
}

Expand Down Expand Up @@ -125,11 +129,10 @@ else if (typeAsString.equalsIgnoreCase("UNIQUE")) {
return total.get();
}

/***
* returns the list of property names to be indexed
/**
* Returns the list of property names to be indexed.
*
* @param ctx
* @return
* @return Array of property names
*/
private String[] calculateProperties(final CommandContext ctx) {
if (propertyList == null) {
Expand All @@ -141,7 +144,10 @@ private String[] calculateProperties(final CommandContext ctx) {
@Override
public void toString(final Map<String, Object> params, final StringBuilder builder) {
builder.append("CREATE INDEX ");
name.toString(params, builder);

if (name != null)
name.toString(params, builder);

if (typeName != null) {
builder.append(" ON ");
typeName.toString(params, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import com.arcadedb.query.sql.executor.ResultInternal;
import com.arcadedb.query.sql.executor.ResultSet;

import java.util.Map;
import java.util.*;

public class DropIndexStatement extends DDLStatement {

protected boolean all = false;
protected IndexName name;
protected boolean ifExists = false;
protected boolean all = false;
protected Identifier name;
protected boolean ifExists = false;

public DropIndexStatement(int id) {
super(id);
Expand Down
Loading