-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3542ab
commit 9146805
Showing
13 changed files
with
142 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
.../src/main/java/org/polypheny/db/workflow/dag/activities/impl/DocSelectFieldsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2019-2025 The Polypheny Project | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.polypheny.db.workflow.dag.activities.impl; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.polypheny.db.algebra.AlgNode; | ||
import org.polypheny.db.algebra.logical.document.LogicalDocumentProject; | ||
import org.polypheny.db.algebra.type.AlgDataType; | ||
import org.polypheny.db.plan.AlgCluster; | ||
import org.polypheny.db.rex.RexNameRef; | ||
import org.polypheny.db.rex.RexNode; | ||
import org.polypheny.db.workflow.dag.activities.Activity; | ||
import org.polypheny.db.workflow.dag.activities.Activity.ActivityCategory; | ||
import org.polypheny.db.workflow.dag.activities.Activity.PortType; | ||
import org.polypheny.db.workflow.dag.activities.ActivityException; | ||
import org.polypheny.db.workflow.dag.activities.Fusable; | ||
import org.polypheny.db.workflow.dag.activities.Pipeable; | ||
import org.polypheny.db.workflow.dag.activities.TypePreview; | ||
import org.polypheny.db.workflow.dag.activities.TypePreview.DocType; | ||
import org.polypheny.db.workflow.dag.annotations.ActivityDefinition; | ||
import org.polypheny.db.workflow.dag.annotations.ActivityDefinition.InPort; | ||
import org.polypheny.db.workflow.dag.annotations.ActivityDefinition.OutPort; | ||
import org.polypheny.db.workflow.dag.annotations.FieldSelectSetting; | ||
import org.polypheny.db.workflow.dag.settings.FieldSelectValue; | ||
import org.polypheny.db.workflow.dag.settings.SettingDef.Settings; | ||
import org.polypheny.db.workflow.dag.settings.SettingDef.SettingsPreview; | ||
import org.polypheny.db.workflow.engine.execution.context.ExecutionContext; | ||
import org.polypheny.db.workflow.engine.execution.context.PipeExecutionContext; | ||
import org.polypheny.db.workflow.engine.execution.pipe.InputPipe; | ||
import org.polypheny.db.workflow.engine.execution.pipe.OutputPipe; | ||
import org.polypheny.db.workflow.engine.storage.reader.CheckpointReader; | ||
|
||
@ActivityDefinition(type = "docSelectFields", displayName = "Select Document Fields", categories = { ActivityCategory.TRANSFORM, ActivityCategory.DOCUMENT, }, | ||
inPorts = { @InPort(type = PortType.DOC, description = "The input collection.") }, | ||
outPorts = { @OutPort(type = PortType.DOC, description = "Collection containing only the specified fields of the input table. The '_id' field is always included.") }, | ||
shortDescription = "Select a subset of (nested) fields of the input collection." | ||
) | ||
@FieldSelectSetting(key = "fields", displayName = "Select Fields", reorder = false, | ||
shortDescription = "Specify which fields to include. Alternatively, you can include any field not present in the list of excluded fields.") | ||
|
||
@SuppressWarnings("unused") | ||
public class DocSelectFieldsActivity implements Activity, Fusable, Pipeable { | ||
|
||
@Override | ||
public List<TypePreview> previewOutTypes( List<TypePreview> inTypes, SettingsPreview settings ) throws ActivityException { | ||
return DocType.of().asOutTypes(); | ||
} | ||
|
||
|
||
@Override | ||
public void execute( List<CheckpointReader> inputs, Settings settings, ExecutionContext ctx ) throws Exception { | ||
Fusable.super.execute( inputs, settings, ctx ); | ||
} | ||
|
||
|
||
@Override | ||
public AlgNode fuse( List<AlgNode> inputs, Settings settings, AlgCluster cluster ) throws Exception { | ||
AlgDataType type = getDocType(); | ||
FieldSelectValue setting = settings.get( "fields", FieldSelectValue.class ); | ||
if ( setting.includeUnspecified() ) { | ||
return LogicalDocumentProject.create( inputs.get( 0 ), Map.of(), setting.getExclude() ); | ||
} | ||
|
||
List<String> fields = setting.getInclude(); | ||
Map<String, RexNode> nameRefs = fields.stream().collect( Collectors.toMap( | ||
field -> field, | ||
field -> RexNameRef.create( List.of( field.split( "\\." ) ), null, type ) | ||
) ); | ||
return LogicalDocumentProject.create( inputs.get( 0 ), nameRefs, setting.getExclude() ); | ||
} | ||
|
||
|
||
@Override | ||
public AlgDataType lockOutputType( List<AlgDataType> inTypes, Settings settings ) throws Exception { | ||
return getDocType(); | ||
} | ||
|
||
|
||
@Override | ||
public void pipe( List<InputPipe> inputs, OutputPipe output, Settings settings, PipeExecutionContext ctx ) throws Exception { | ||
throw new NotImplementedException( "Pipe is not yet implemented." ); | ||
} | ||
|
||
|
||
@Override | ||
public Optional<Boolean> canPipe( List<TypePreview> inTypes, SettingsPreview settings ) { | ||
return Optional.of( false ); // TODO: implement pipe | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters