com.arcadedb.query.sql.method.misc.SQLMethodExclude Maven / Gradle / Ivy
/*
* Copyright 2022 Arcade Data Ltd
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
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 excluding only some fields. If the content is a document, then creates a
* copy without the excluded fields. If it's a collection of documents it acts against on each
* single entry.
*
*
*
*
Syntax:
*
*
*
*
*
*
* exclude(<field|value|expression> [,<field-name>]* )
*
*
*
*
*
*
*
*
*
Examples:
*
*
*
*
*
*
* SELECT exclude(roles, 'permissions') FROM OUser
*
*
*
*
*
*
* @author Luca Garulli (l.garulli--(at)--orientdb.com)
*/
public class SQLMethodExclude extends AbstractSQLMethod {
public static final String NAME = "exclude";
public SQLMethodExclude() {
super(NAME, 1, -1);
}
@Override
public String getSyntax() {
return "Syntax error: exclude([][,]*)";
}
@Override
public Object execute(Object current, final Identifiable iCurrentRecord, final CommandContext iContext, final Object ioResult, final Object[] iParams) {
if (current != 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 SINGLE 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