8000 Feature/aql interleave function by maierlars · Pull Request #11352 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/aql interleave function #11352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Next Next commit
Draft for INTERLEAVE function in aql. (still buggy)
  • Loading branch information
lamai93 committed Mar 25, 2020
commit 81cf9ea810e2a03181a00a74129b60b900e4b7e8
1 change: 1 addition & 0 deletions arangod/Aql/AqlFunctionFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void AqlFunctionFeature::addListFunctions() {
add({"REMOVE_VALUES", ".,.", flags, &Functions::RemoveValues});
add({"REMOVE_NTH", ".,.", flags, &Functions::RemoveNth});
add({"REPLACE_NTH", ".,.,.|.", flags, &Functions::ReplaceNth});
add({"INTERLEAVE", ".,.|+", flags, &Functions::Interleave});

// special flags:
// CALL and APPLY will always run on the coordinator and are not deterministic
Expand Down
51 changes: 51 additions & 0 deletions arangod/Aql/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7523,3 +7523,54 @@ AqlValue Functions::NotImplemented(ExpressionContext* expressionContext,
registerError(expressionContext, "UNKNOWN", TRI_ERROR_NOT_IMPLEMENTED);
return AqlValue(AqlValueHintNull());
}

AqlValue Functions::Interleave(arangodb::aql::ExpressionContext* expressionContext,
transaction::Methods* trx, VPackFunctionParameters const& parameters) {
// cppcheck-suppress variableScope
static char const* AFN = "INTERLEAVE";

struct ArrayPairs {
AqlValueMaterializer materializer;
VPackSlice slice;
VPackArrayIterator current;
VPackArrayIterator end;

};

std::list<ArrayPairs> iters;
for (AqlValue const& parameter : parameters) {
AqlValueMaterializer materializer(trx);
VPackSlice slice = materializer.slice(parameter, false);

if (!slice.isArray()) {
// not an array
registerWarning(expressionContext, AFN, TRI_ERROR_QUERY_ARRAY_EXPECTED);
return AqlValue(AqlValueHintNull());
} else if (slice.isEmptyArray()) {
continue; // skip empty array here
}

VPackArrayIterator iter(slice);
ArrayPairs pair{std::move(materializer), slice, iter.begin(), iter.end()};
iters.emplace_back(std::move(pair));
}

transaction::BuilderLeaser builder(trx);
builder->openArray();

while (!iters.empty()) { // in this loop we only deal with nonempty arrays
for (auto i = iters.begin(); i != iters.end();) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, not that easy to grasp but correct!

builder->add(i->current.value()); // thus this will always be valid on the first iteration

i->current++;
if (i->current == i->end) {
i = iters.erase(i);
} else {
i++;
}
}
}

builder->close();
return AqlValue(builder.get());
}
4 changes: 3 additions & 1 deletion arangod/Aql/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct Functions {
static AqlValue NgramSimilarity(ExpressionContext*, transaction::Methods*,
VPackFunctionParameters const&);
static AqlValue NgramPositionalSimilarity(ExpressionContext* ctx,
transaction::Methods*,
transaction::Methods*,
VPackFunctionParameters const&);
static AqlValue NgramMatch(ExpressionContext*, transaction::Methods*,
VPackFunctionParameters const&);
Expand Down Expand Up @@ -427,6 +427,8 @@ struct Functions {
transaction::Methods*, VPackFunctionParameters const&);
static AqlValue ReplaceNth(arangodb::aql::ExpressionContext*,
transaction::Methods*, VPackFunctionParameters const&);
static AqlValue Interleave(arangodb::aql::ExpressionContext*,
transaction::Methods*, VPackFunctionParameters const&);
static AqlValue NotNull(arangodb::aql::ExpressionContext*,
transaction::Methods*, VPackFunctionParameters const&);
static AqlValue CurrentDatabase(arangodb::aql::ExpressionContext*,
Expand Down
0