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
21 changes: 20 additions & 1 deletion engine/src/main/grammar/SQLGrammar.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ TOKEN:
|
< CREATE: ( "c" | "C" ) ( "r" | "R" ) ( "e" | "E" ) ( "a" | "A" ) ( "t" | "T" ) ( "e" | "E" ) >
|
< CUSTOM: ( "c" | "C" ) ( "u" | "U" ) ( "s" | "S" ) ( "t" | "T" ) ( "o" | "O" ) ( "m" | "M" ) >
|
< DELETE: ( "d" | "D" ) ( "e" | "E" ) ( "l" | "L" ) ( "e" | "E" ) ( "t" | "T" ) ( "e" | "E" ) >
|
< DOCUMENT: ( "d" | "D" ) ( "o" | "O" ) ( "c" | "C" ) ( "u" | "U" ) ( "m" | "M" ) ( "e" | "E" ) ( "n" | "N" ) ( "t" | "T" ) >
Expand Down Expand Up @@ -746,6 +748,8 @@ Identifier Identifier():
|
token = <STORAGE>
|
token = <CUSTOM>
|
token = <ON>
|
token = <OFF>
Expand Down Expand Up @@ -3745,6 +3749,13 @@ AlterTypeStatement AlterTypeStatement():
lastIdentifier = Identifier() { jjtThis.identifierListValue.add(lastIdentifier); }
)*
)
|
(
<CUSTOM>
jjtThis.customKey = Identifier()
<EQ>
jjtThis.customValue = Expression()
)
)
{ return jjtThis; }
}
Expand Down Expand Up @@ -3815,8 +3826,16 @@ AlterPropertyStatement AlterPropertyStatement():
<DOT>
jjtThis.propertyName = Identifier()
(
LOOKAHEAD(3)
(
<CUSTOM>
jjtThis.customPropertyName = Identifier()
<EQ>
jjtThis.customPropertyValue = Expression()
)
|
(
jjtThis.settingName = Identifier()
jjtThis.settingName = Identifier()
jjtThis.settingValue = Expression()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_USERTYPE_VISIBILITY_PUBLIC=true */
package com.arcadedb.query.sql.parser;

import com.arcadedb.database.Database;
import com.arcadedb.database.Identifiable;
import com.arcadedb.exception.CommandExecutionException;
import com.arcadedb.exception.CommandSQLParsingException;
import com.arcadedb.query.sql.executor.CommandContext;
import com.arcadedb.query.sql.executor.InternalResultSet;
import com.arcadedb.query.sql.executor.ResultInternal;
import com.arcadedb.query.sql.executor.ResultSet;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.Property;

import java.util.*;

Expand All @@ -43,58 +50,46 @@ public AlterPropertyStatement(SqlParser p, int id) {

@Override
public ResultSet executeDDL(CommandContext ctx) {
Database db = ctx.getDatabase();
DocumentType typez = db.getSchema().getType(typeName.getStringValue());

if (typez == null) {
throw new CommandExecutionException("Invalid type name or type not found: " + typez);
}

Property property = typez.getProperty(propertyName.getStringValue());
if (property == null) {
throw new CommandExecutionException("Property " + property + " not found on type " + typez);
}

ResultInternal result = new ResultInternal();
result.setProperty("type", typeName.getStringValue());
result.setProperty("property", propertyName.getStringValue());

if (customPropertyName != null) {
String customName = customPropertyName.getStringValue();
Object oldValue = property.getCustomValue(customName);
Object finalValue = customPropertyValue.execute((Identifiable) null, ctx);
property.setCustomValue(customName, finalValue == null ? null : finalValue);

result.setProperty("operation", "alter property custom");
result.setProperty("customAttribute", customPropertyName.getStringValue());
result.setProperty("oldValue", oldValue != null ? oldValue : null);
result.setProperty("newValue", finalValue != null ? finalValue : null);
} else {
throw new UnsupportedOperationException();

throw new UnsupportedOperationException();
// Database db = ctx.getDatabase();
// OClass typez = db.getMetadata().getSchema().getClass(className.getStringValue());
//
// if (typez == null) {
// throw new PCommandExecutionException("Invalid class name or class not found: " + typez);
// }
//
// OProperty property = typez.getProperty(propertyName.getStringValue());
// if (property == null) {
// throw new PCommandExecutionException("Property " + property + " not found on class " + typez);
// }
//
// OResultInternal result = new OResultInternal();
// result.setProperty("class", className.getStringValue());
// result.setProperty("property", propertyName.getStringValue());
//
// if (customPropertyName != null) {
// String customName = customPropertyName.getStringValue();
// Object oldValue = property.getCustom(customName);
// Object finalValue = customPropertyValue.execute((PIdentifiable) null, ctx);
// property.setCustom(customName, finalValue == null ? null : "" + finalValue);
//
// result.setProperty("operation", "alter property custom");
// result.setProperty("customAttribute", customPropertyName.getStringValue());
// result.setProperty("oldValue", oldValue != null ? oldValue.toString() : null);
// result.setProperty("newValue", finalValue != null ? finalValue.toString() : null);
// } else {
// String setting = settingName.getStringValue();
// Object finalValue = settingValue.execute((PIdentifiable) null, ctx);
//
// OProperty.ATTRIBUTES attribute;
// try {
// attribute = OProperty.ATTRIBUTES.valueOf(setting.toUpperCase(Locale.ENGLISH));
// } catch (IllegalArgumentException e) {
// throw OException.wrapException(new PCommandExecutionException(
// "Unknown property attribute '" + setting + "'. Supported attributes are: " + Arrays
// .toString(OProperty.ATTRIBUTES.values())), e);
// }
// Object oldValue = property.get(attribute);
// property.set(attribute, finalValue);
// finalValue = property.get(attribute);//it makes some conversions...
// Object finalValue = settingValue.execute((Identifiable) null, ctx);
//
// result.setProperty("operation", "alter property");
// result.setProperty("attribute", setting);
// result.setProperty("oldValue", oldValue != null ? oldValue.toString() : null);
// result.setProperty("newValue", finalValue != null ? finalValue.toString() : null);
// }
// OInternalResultSet rs = new OInternalResultSet();
// rs.add(result);
// return rs;
}
InternalResultSet rs = new InternalResultSet();
rs.add(result);
return rs;
}

@Override
Expand Down Expand Up @@ -140,7 +135,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass())
return false;

AlterPropertyStatement that = (AlterPropertyStatement) o;
final AlterPropertyStatement that = (AlterPropertyStatement) o;

if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=O,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_USERTYPE_VISIBILITY_PUBLIC=true */
package com.arcadedb.query.sql.parser;

import com.arcadedb.database.Identifiable;
import com.arcadedb.exception.CommandExecutionException;
import com.arcadedb.query.sql.executor.CommandContext;
import com.arcadedb.query.sql.executor.InternalResultSet;
Expand All @@ -42,11 +43,8 @@ public class AlterTypeStatement extends DDLStatement {
protected List<Identifier> identifierListValue = new ArrayList<>();
protected PNumber numberValue;
protected Boolean booleanValue;

// only to manage 'round-robin' as a bucket selection strategy (not a valid identifier)
protected String customString;

protected boolean unsafe;
protected Identifier customKey;
protected Expression customValue;

public AlterTypeStatement(int id) {
super(id);
Expand All @@ -60,8 +58,28 @@ public AlterTypeStatement(SqlParser p, int id) {
public void toString(Map<String, Object> params, StringBuilder builder) {
builder.append("ALTER TYPE ");
name.toString(params, builder);
if (property != null)
if (property != null) {
builder.append(" " + property + " ");

if (numberValue != null) {
numberValue.toString(params, builder); // clusters only
} else if (identifierValue != null) {
identifierValue.toString(params, builder);
} else {
builder.append("null");
}
}

if (customKey != null) {
builder.append(" CUSTOM ");
customKey.toString(params, builder);
builder.append("=");
if (customValue == null) {
builder.append("null");
} else {
customValue.toString(params, builder);
}
}
}

public Statement copy() {
Expand All @@ -72,8 +90,8 @@ public Statement copy() {
result.identifierListAddRemove = new ArrayList<>(identifierListAddRemove);
result.numberValue = numberValue == null ? null : numberValue.copy();
result.booleanValue = booleanValue;
result.customString = customString;
result.unsafe = unsafe;
result.customKey = customKey == null ? null : customKey.copy();
result.customValue = customValue == null ? null : customValue.copy();
return result;
}

Expand All @@ -86,8 +104,6 @@ public boolean equals(Object o) {

final AlterTypeStatement that = (AlterTypeStatement) o;

if (unsafe != that.unsafe)
return false;
if (name != null ? !name.equals(that.name) : that.name != null)
return false;
if (property != that.property)
Expand All @@ -100,7 +116,11 @@ public boolean equals(Object o) {
return false;
if (booleanValue != null ? !booleanValue.equals(that.booleanValue) : that.booleanValue != null)
return false;
return customString != null ? customString.equals(that.customString) : that.customString == null;
if (customKey != null ? !customKey.equals(that.customKey) : that.customKey != null)
return false;
if (customValue != null ? !customValue.equals(that.customValue) : that.customValue != null)
return false;
return true;
}

@Override
Expand All @@ -111,8 +131,8 @@ public int hashCode() {
result = 31 * result + identifierListAddRemove.hashCode();
result = 31 * result + (numberValue != null ? numberValue.hashCode() : 0);
result = 31 * result + (booleanValue != null ? booleanValue.hashCode() : 0);
result = 31 * result + (customString != null ? customString.hashCode() : 0);
result = 31 * result + (unsafe ? 1 : 0);
result = 31 * result + (customKey != null ? customKey.hashCode() : 0);
result = 31 * result + (customValue != null ? customValue.hashCode() : 0);
return result;
}

Expand Down Expand Up @@ -164,19 +184,26 @@ else if (numberValue != null)
}
}

if (customKey != null) {
Object value = null;
if (customValue != null)
value = customValue.execute((Identifiable) null, ctx);

type.setCustomValue(customKey.getStringValue(), value);
}

final InternalResultSet resultSet = new InternalResultSet();
ResultInternal result = new ResultInternal();
final ResultInternal result = new ResultInternal();
result.setProperty("operation", "ALTER TYPE");
result.setProperty("typeName", name.getStringValue());
result.setProperty("result", "OK");
return resultSet;
}

private void doSetSuperType(final CommandContext ctx, final DocumentType oClass) {
private void doSetSuperType(final CommandContext ctx, final DocumentType type) {
if (identifierListValue == null)
throw new CommandExecutionException("Invalid super type names");

final List<DocumentType> superclasses = new ArrayList<>();
for (int i = 0; i < identifierListValue.size(); i++) {
final Identifier superTypeName = identifierListValue.get(i);
final Boolean add = identifierListAddRemove.get(i);
Expand All @@ -186,9 +213,9 @@ private void doSetSuperType(final CommandContext ctx, final DocumentType oClass)
throw new CommandExecutionException("Super type '" + superTypeName.getStringValue() + "' not found");

if (add)
oClass.addSuperType(superclass);
type.addSuperType(superclass);
else
oClass.removeSuperType(superclass);
type.removeSuperType(superclass);
}
}
}
Expand Down
Loading