![JAR search and dependency download from the Maven repository](/logo.png)
sparksoniq.jsoniq.runtime.iterator.functions.object.ObjectValuesFunctionIterator Maven / Gradle / Ivy
/*
* 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.
*
* Authors: Stefan Irimescu, Can Berker Cikis
*
*/
package sparksoniq.jsoniq.runtime.iterator.functions.object;
import sparksoniq.exceptions.IteratorFlowException;
import sparksoniq.jsoniq.runtime.iterator.HybridRuntimeIterator;
import sparksoniq.jsoniq.runtime.iterator.RuntimeIterator;
import sparksoniq.jsoniq.runtime.metadata.IteratorMetadata;
import sparksoniq.semantics.DynamicContext;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.rumbledb.api.Item;
public class ObjectValuesFunctionIterator extends HybridRuntimeIterator {
private static final long serialVersionUID = 1L;
private RuntimeIterator _iterator;
private Queue- _nextResults; // queue that holds the results created by the current item in inspection
public ObjectValuesFunctionIterator(List
arguments, IteratorMetadata iteratorMetadata) {
super(arguments, iteratorMetadata);
_iterator = arguments.get(0);
}
@Override
public void openLocal(DynamicContext context) {
_iterator.open(context);
_nextResults = new LinkedList<>();
setNextResult();
}
@Override
public Item nextLocal() {
if (this._hasNext) {
Item result = _nextResults.remove(); // save the result to be returned
if (_nextResults.isEmpty()) {
// if there are no more results left in the queue, trigger calculation for the next result
setNextResult();
}
return result;
}
throw new IteratorFlowException(RuntimeIterator.FLOW_EXCEPTION_MESSAGE + " VALUES function",
getMetadata());
}
@Override
protected boolean hasNextLocal() {
return _hasNext;
}
@Override
protected void resetLocal(DynamicContext context) {
_iterator.reset(_currentDynamicContext);
setNextResult();
}
@Override
protected void closeLocal() {
_iterator.close();
}
public void setNextResult() {
while (_iterator.hasNext()) {
Item item = _iterator.next();
if (item.isObject()) {
_nextResults.addAll(item.getValues());
if (!(_nextResults.isEmpty())) {
break;
}
}
}
if (_nextResults.isEmpty()) {
this._hasNext = false;
_iterator.close();
} else {
this._hasNext = true;
}
}
@Override
public JavaRDD- getRDD(DynamicContext dynamicContext) {
_currentDynamicContext = dynamicContext;
JavaRDD
- childRDD = _iterator.getRDD(dynamicContext);
FlatMapFunction
- transformation = new ObjectValuesClosure();
return childRDD.flatMap(transformation);
}
@Override
public boolean initIsRDD() {
return _iterator.isRDD();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy