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
42 changes: 27 additions & 15 deletions engine/src/main/java/com/arcadedb/query/sql/parser/Projection.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.executor.ResultInternal;

import java.util.*;
import java.util.stream.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class Projection extends SimpleNode {

Expand Down Expand Up @@ -94,8 +99,9 @@ public Result calculateSingle(final CommandContext context, final Result record)
if (isExpand())
throw new IllegalStateException("This is an expand projection, it cannot be calculated as a single result" + this);

if (items.size() == 1 && items.get(0).getExpression().toString().equals("@this")
&& items.get(0).nestedProjection == null)
if (items.size() == 1 &&
items.get(0).getExpression().toString().equals("@this") &&
items.get(0).nestedProjection == null)
return record;

final ResultInternal result = new ResultInternal(context.getDatabase());
Expand All @@ -104,26 +110,32 @@ public Result calculateSingle(final CommandContext context, final Result record)
continue;

if (item.isAll()) {
final Document doc = record.getElement().get();
for (final String alias : record.getPropertyNames()) {
if (this.excludes.contains(alias)
|| (doc.getType().existsProperty(alias) && doc.getType().getProperty(alias).isHidden())) {
if (excludes.contains(alias)) {
continue;
} else if (record.getElement().isPresent()) {
final Document doc = record.getElement().get();
if (excludes.contains(alias) ||
(doc.getType().existsProperty(alias) &&
doc.getType().getProperty(alias).isHidden())) {
continue;
}
}
Object val = item.convert(record.getProperty(alias));
Object value = item.convert(record.getProperty(alias));
if (item.nestedProjection != null) {
val = item.nestedProjection.apply(item.expression, val, context);
value = item.nestedProjection.apply(item.expression, value, context);
}
result.setProperty(alias, val);
result.setProperty(alias, value);
}
if (record.getElement().isPresent()) {
if (!this.excludes.contains("@rid")) {

record.getElement().ifPresent(doc -> {
if (!excludes.contains("@rid")) {
result.setProperty("@rid", doc.getIdentity());
}
if (!this.excludes.contains("@type")) {
if (!excludes.contains("@type")) {
result.setProperty("@type", doc.getType().getName());
}
}
});
} else {
result.setProperty(item.getProjectionAliasAsString(), item.execute(record, context));
}
Expand All @@ -138,7 +150,7 @@ public Result calculateSingle(final CommandContext context, final Result record)

private void initExcludes() {
if (excludes == null) {
this.excludes = new HashSet<String>();
this.excludes = new HashSet<>();
for (final ProjectionItem item : items) {
if (item.exclude)
this.excludes.add(item.getProjectionAliasAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

import com.arcadedb.TestHelper;
import com.arcadedb.database.RID;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

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

import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Luigi Dell'Aquila (l.dellaquila-(at)-orientdb.com)
Expand Down Expand Up @@ -180,23 +179,20 @@ public void testBreadthFirst() {
@Test
public void testTraverseInBatchTx() {
database.transaction(() -> {
String script = "";
script += "";

script += "drop type testTraverseInBatchTx_V if exists unsafe;";
script += "create vertex type testTraverseInBatchTx_V;";
script += "create property testTraverseInBatchTx_V.name STRING;";
script += "drop type testTraverseInBatchTx_E if exists unsafe;";
script += "create edge type testTraverseInBatchTx_E;";

script += "begin;";
script += "insert into testTraverseInBatchTx_V(name) values ('a'), ('b'), ('c');";
script += "create edge testTraverseInBatchTx_E from (select from testTraverseInBatchTx_V where name = 'a') to (select from testTraverseInBatchTx_V where name = 'b');";
script += "create edge testTraverseInBatchTx_E from (select from testTraverseInBatchTx_V where name = 'b') to (select from testTraverseInBatchTx_V where name = 'c');";
script += "let top = (select * from (traverse in('testTraverseInBatchTx_E') from (select from testTraverseInBatchTx_V where name='c')) where in('testTraverseInBatchTx_E').size() == 0);";
script += "commit;";
script += "return $top;";

String script = """
drop type testTraverseInBatchTx_V if exists unsafe;
create vertex type testTraverseInBatchTx_V;
create property testTraverseInBatchTx_V.name STRING;
drop type testTraverseInBatchTx_E if exists unsafe;
create edge type testTraverseInBatchTx_E;
begin;
insert into testTraverseInBatchTx_V(name) values ('a'), ('b'), ('c');
create edge testTraverseInBatchTx_E from (select from testTraverseInBatchTx_V where name = 'a') to (select from testTraverseInBatchTx_V where name = 'b');
create edge testTraverseInBatchTx_E from (select from testTraverseInBatchTx_V where name = 'b') to (select from testTraverseInBatchTx_V where name = 'c');
let top = (select * from (traverse in('testTraverseInBatchTx_E') from (select from testTraverseInBatchTx_V where name='c')) where in('testTraverseInBatchTx_E').size() == 0);
commit;
return $top;
""";
final ResultSet result = database.command("sqlscript", script);
assertThat(result.hasNext()).isTrue();
result.next();
Expand Down
Loading