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
2 changes: 1 addition & 1 deletion engine/src/main/grammar/SQLGrammar.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4557,7 +4557,7 @@ ExportDatabaseStatement ExportDatabaseStatement():
(
<EXPORT> <DATABASE>
jjtThis.url = Url()
[ <FORMAT> jjtThis.format = PString() ]
[ <FORMAT> jjtThis.format = Identifier() ]
[ <OVERWRITE> ( <TRUE> { jjtThis.overwrite = BooleanExpression.TRUE;} | <FALSE> { jjtThis.overwrite = BooleanExpression.FALSE;} ) ]
)
{return jjtThis; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ else if (type.getType() == Edge.RECORD_TYPE)
propRes.setProperty("name", typeIndexInternal.getName());
propRes.setProperty("typeName", typeIndexInternal.getTypeName());
propRes.setProperty("type", typeIndexInternal.getType());
propRes.setProperty("properties", Arrays.asList(typeIndexInternal.getPropertyNames()));
propRes.setProperty("properties", typeIndexInternal.getPropertyNames());
propRes.setProperty("automatic", typeIndexInternal.isAutomatic());
propRes.setProperty("unique", typeIndexInternal.isUnique());
return propRes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +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.exception.CommandExecutionException;
import com.arcadedb.index.Index;
import com.arcadedb.index.IndexInternal;
import com.arcadedb.index.TypeIndex;
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 java.util.*;

Expand All @@ -27,7 +35,7 @@ public class DropPropertyStatement extends DDLStatement {
protected Identifier typeName;
protected Identifier propertyName;
protected boolean ifExists = false;
protected boolean force = false;
protected boolean force = false;

public DropPropertyStatement(int id) {
super(id);
Expand All @@ -37,85 +45,75 @@ public DropPropertyStatement(SqlParser p, int id) {
super(p, id);
}

@Override public ResultSet executeDDL(CommandContext ctx) {

throw new UnsupportedOperationException();
// InternalResultSet rs = new InternalResultSet();
// final Database database = ctx.getDatabase();
// final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className.getStringValue());
// if (sourceClass == null)
// throw new PCommandExecutionException("Source class '" + className + "' not found");
//
// if (sourceClass.getProperty(propertyName.getStringValue()) == null) {
// if(ifExists){
// return rs;
// }
// throw new PCommandExecutionException("Property '" + propertyName + "' not found on class " + className);
// }
// final List<OIndex<?>> indexes = relatedIndexes(propertyName.getStringValue(), database);
// if (!indexes.isEmpty()) {
// if (force) {
// for (final OIndex<?> index : indexes) {
// index.delete();
// OResultInternal result = new OResultInternal();
// result.setProperty("operation", "cascade drop index");
// result.setProperty("indexName", index.getName());
// rs.add(result);
// }
// } else {
// final StringBuilder indexNames = new StringBuilder();
//
// boolean first = true;
// for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(propertyName.getStringValue())) {
// if (!first) {
// indexNames.append(", ");
// } else {
// first = false;
// }
// indexNames.append(index.getName());
// }
//
// throw new PCommandExecutionException("Property used in indexes (" + indexNames.toString()
// + "). Please drop these indexes before removing property or use FORCE parameter.");
// }
// }
//
// // REMOVE THE PROPERTY
// sourceClass.dropProperty(propertyName.getStringValue());
//
// OResultInternal result = new OResultInternal();
// result.setProperty("operation", "drop property");
// result.setProperty("typeName", className.getStringValue());
// result.setProperty("propertyname", propertyName.getStringValue());
// rs.add(result);
// return rs;
@Override
public ResultSet executeDDL(CommandContext ctx) {
InternalResultSet rs = new InternalResultSet();
final Database database = ctx.getDatabase();
final DocumentType sourceClass = database.getSchema().getType(typeName.getStringValue());
if (sourceClass == null)
throw new CommandExecutionException("Source class '" + typeName + "' not found");

if (sourceClass.getProperty(propertyName.getStringValue()) == null) {
if (ifExists) {
return rs;
}
throw new CommandExecutionException("Property '" + propertyName + "' not found on class " + typeName);
}
final List<TypeIndex> indexes = sourceClass.getIndexesByProperty(propertyName.getStringValue());
if (!indexes.isEmpty()) {
if (force) {
for (final Index index : indexes) {
((IndexInternal) index).drop();
ResultInternal result = new ResultInternal();
result.setProperty("operation", "cascade drop index");
result.setProperty("indexName", index.getName());
rs.add(result);
}
} else {
final StringBuilder indexNames = new StringBuilder();

boolean first = true;
for (final TypeIndex index : indexes) {
if (!first) {
indexNames.append(", ");
} else {
first = false;
}
indexNames.append(index.getName());
}

throw new CommandExecutionException(
"Property used in indexes (" + indexNames + "). Please drop these indexes before removing property or use FORCE parameter.");
}
}

// REMOVE THE PROPERTY
sourceClass.dropProperty(propertyName.getStringValue());

ResultInternal result = new ResultInternal();
result.setProperty("operation", "drop property");
result.setProperty("typeName", typeName.getStringValue());
result.setProperty("propertyName", propertyName.getStringValue());
rs.add(result);
return rs;
}

// private List<OIndex<?>> relatedIndexes(final String fieldName, ODatabase database) {
// final List<OIndex<?>> result = new ArrayList<OIndex<?>>();
// for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className.getStringValue())) {
// if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) {
// result.add(oIndex);
// }
// }
//
// return result;
// }

@Override public void toString(Map<String, Object> params, StringBuilder builder) {
@Override
public void toString(Map<String, Object> params, StringBuilder builder) {
builder.append("DROP PROPERTY ");
typeName.toString(params, builder);
builder.append(".");
propertyName.toString(params, builder);
if(ifExists){
if (ifExists) {
builder.append(" IF EXISTS");
}
if(force){
if (force) {
builder.append(" FORCE");
}
}

@Override public DropPropertyStatement copy() {
@Override
public DropPropertyStatement copy() {
DropPropertyStatement result = new DropPropertyStatement(-1);
result.typeName = typeName == null ? null : typeName.copy();
result.propertyName = propertyName == null ? null : propertyName.copy();
Expand All @@ -124,7 +122,8 @@ public DropPropertyStatement(SqlParser p, int id) {
return result;
}

@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
Expand All @@ -134,15 +133,16 @@ public DropPropertyStatement(SqlParser p, int id) {

if (force != that.force)
return false;
if(ifExists!=that.ifExists){
if (ifExists != that.ifExists) {
return false;
}
if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
return false;
return propertyName != null ? propertyName.equals(that.propertyName) : that.propertyName == null;
}

@Override public int hashCode() {
@Override
public int hashCode() {
int result = typeName != null ? typeName.hashCode() : 0;
result = 31 * result + (propertyName != null ? propertyName.hashCode() : 0);
result = 31 * result + (force ? 1 : 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class ExportDatabaseStatement extends SimpleExecStatement {

protected Url url;
protected String format = "jsonl";
protected Identifier format = new Identifier("jsonl");
protected BooleanExpression overwrite = BooleanExpression.FALSE;

public ExportDatabaseStatement(int id) {
Expand Down Expand Up @@ -58,7 +58,7 @@ public ResultSet executeSimple(CommandContext ctx) {
final Class<?> clazz = Class.forName("com.arcadedb.integration.exporter.Exporter");
final Object exporter = clazz.getConstructor(Database.class, String.class).newInstance(ctx.getDatabase(), fileName);

String formatExport = format;
String formatExport = format.getStringValue();
if ((formatExport.startsWith("'") && formatExport.endsWith("'")) ||//
formatExport.startsWith("\"") && formatExport.endsWith("\"")) {
formatExport = formatExport.substring(1, formatExport.length() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17672,7 +17672,7 @@ final public ExportDatabaseStatement ExportDatabaseStatement() throws ParseExcep
switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) {
case FORMAT:{
jj_consume_token(FORMAT);
jjtn000.format = PString();
jjtn000.format = Identifier();
break;
}
default:
Expand Down Expand Up @@ -21278,7 +21278,7 @@ private boolean jj_3_88()
private boolean jj_3R_706()
{
if (jj_scan_token(FORMAT)) return true;
if (jj_3R_490()) return true;
if (jj_3R_128()) return true;
return false;
}

Expand Down
15 changes: 15 additions & 0 deletions engine/src/main/java/com/arcadedb/schema/DocumentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ public List<Index> getPolymorphicBucketIndexByBucketId(final int bucketId) {
return result;
}

public List<TypeIndex> getIndexesByProperty(final String property) {
final List<TypeIndex> result = new ArrayList<>();

for (Map.Entry<List<String>, TypeIndex> entry : indexesByProperties.entrySet()) {
for (String prop : entry.getKey()) {
if (property.equals(prop)) {
result.add(entry.getValue());
break;
}
}
}

return result;
}

public TypeIndex getPolymorphicIndexByProperties(final String... properties) {
return getPolymorphicIndexByProperties(Arrays.asList(properties));
}
Expand Down
Loading