com.arcadedb.query.sql.method.misc.SQLMethodInclude Maven / Gradle / Ivy
/*
* Copyright © 2021-present Arcade Data Ltd ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: 2021-present Arcade Data Ltd ([email protected])
* SPDX-License-Identifier: Apache-2.0
*/
package com.arcadedb.query.sql.method.misc;
import com.arcadedb.database.Document;
import com.arcadedb.database.Identifiable;
import com.arcadedb.database.MutableDocument;
import com.arcadedb.query.sql.executor.CommandContext;
import com.arcadedb.query.sql.executor.MultiValue;
import com.arcadedb.query.sql.executor.Result;
import com.arcadedb.query.sql.method.AbstractSQLMethod;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.schema.LocalEdgeType;
import com.arcadedb.schema.LocalVertexType;
import java.util.*;
/**
* Filter the content by including only some fields. If the content is a document, then creates a
* copy with only the included fields. If it's a collection of documents it acts against on each
* single entry.
*
*
*
*
Syntax:
*
*
*
*
*
*
* include(<field|value|expression> [,<field-name>]* )
*
*
*
*
*
*
*
*
*
Examples:
*
*
*
*
*
*
* SELECT include(roles, 'name') FROM OUser
*
*
*
*
*
*
* @author Luca Garulli (l.garulli--(at)--orientdb.com)
*/
public class SQLMethodInclude extends AbstractSQLMethod {
public static final String NAME = "include";
public SQLMethodInclude() {
super(NAME, 1, -1);
}
@Override
public String getSyntax() {
return "Syntax error: include([][,]*)";
}
@Override
public Object execute(Object current, final Identifiable iCurrentRecord, final CommandContext iContext, final Object ioResult, final Object[] iParams) {
if (iParams[0] != null) {
if (current instanceof Identifiable)
current = ((Identifiable) current).getRecord();
else if (current instanceof Result)
return copy(((Result) current).toMap(), iParams);
if (current instanceof Document) {
// ACT ON SINGLE DOCUMENT
return copy((Document) current, iParams);
} else if (current instanceof Map) {
// ACT ON MAP
return copy((Map) current, iParams);
} else if (MultiValue.isMultiValue(current)) {
// ACT ON MULTIPLE DOCUMENTS
final int size = MultiValue.getSizeIfAvailable(current);
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy