Skip to content

Commit 4e29bb8

Browse files
committed
Use lid fragment only to access workflow outputs by name
Signed-off-by: Ben Sherman <[email protected]>
1 parent ff81500 commit 4e29bb8

12 files changed

+94
-382
lines changed

modules/nf-lineage/src/main/nextflow/lineage/DefaultLinStore.groovy

+2-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ class DefaultLinStore implements LinStore {
9494
void close() throws IOException { }
9595

9696
@Override
97-
Map<String, LinSerializable> search(String queryString) {
98-
def params = null
99-
if (queryString) {
100-
params = LinUtils.parseQuery(queryString)
101-
}
97+
Map<String, LinSerializable> search(Map<String,String> params) {
98+
new LinPropertyValidator().validateQueryParams(params)
10299
return searchAllFiles(params)
103100
}
104101

modules/nf-lineage/src/main/nextflow/lineage/LinStore.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ interface LinStore extends Closeable {
5555

5656
/**
5757
* Search for lineage entries.
58-
* @queryString Json-path like query string. (Only simple and nested field operators are supported(No array, wildcards,etc.)
59-
* @return Key-lineage entry pairs fulfilling the queryString
58+
* @param params map of query params
59+
* @return Key-lineage entry pairs fulfilling the query params
6060
*/
61-
Map<String,LinSerializable> search(String queryString)
61+
Map<String,LinSerializable> search(Map<String,String> params)
6262

6363
}

modules/nf-lineage/src/main/nextflow/lineage/LinUtils.groovy

-118
Original file line numberDiff line numberDiff line change
@@ -37,107 +37,6 @@ class LinUtils {
3737

3838
private static final String[] EMPTY_ARRAY = new String[] {}
3939

40-
/**
41-
* Query a lineage store.
42-
*
43-
* @param store lineage store to query.
44-
* @param uri Query to perform in a URI-like format.
45-
* Format 'lid://<key>[?QueryString][#fragment]' where:
46-
* - Key: Element where the query will be applied. '/' indicates query will be applied in all the elements of the lineage store.
47-
* - QueryString: all param-value pairs that the lineage element should fulfill in a URI's query string format.
48-
* - Fragment: Element fragment to retrieve.
49-
* @return Collection of object fulfilling the query
50-
*/
51-
static Collection query(LinStore store, URI uri) {
52-
String key = uri.authority ? uri.authority + uri.path : uri.path
53-
if (key == LinPath.SEPARATOR) {
54-
return globalSearch(store, uri)
55-
} else {
56-
final parameters = uri.query ? parseQuery(uri.query) : null
57-
final children = parseChildrenFromFragment(uri.fragment)
58-
return searchPath(store, key, parameters, children )
59-
}
60-
}
61-
62-
private static Collection<LinSerializable> globalSearch(LinStore store, URI uri) {
63-
final results = store.search(uri.query).values()
64-
if (results && uri.fragment) {
65-
// If fragment is defined get the property of the object indicated by the fragment
66-
return filterResults(results, uri.fragment)
67-
}
68-
return results
69-
}
70-
71-
private static List filterResults(Collection<LinSerializable> results, String fragment) {
72-
final filteredResults = []
73-
results.forEach {
74-
final output = navigate(it, fragment)
75-
if (output) {
76-
filteredResults.add(output)
77-
}
78-
}
79-
return filteredResults
80-
}
81-
82-
/**
83-
* Get the array of the search path children elements from the fragment string
84-
*
85-
* @param fragment String containing the elements separated by '.'
86-
* @return array with the parsed element
87-
*/
88-
static String[] parseChildrenFromFragment(String fragment) {
89-
if( !fragment )
90-
return EMPTY_ARRAY
91-
final children = fragment.tokenize('.')
92-
new LinPropertyValidator().validate(children)
93-
return children as String[]
94-
}
95-
96-
/**
97-
* Search for objects inside a description
98-
*
99-
* @param store lineage store
100-
* @param key lineage key where to perform the search
101-
* @param params Parameter-value pairs to be evaluated in the key
102-
* @param children Sub-objects to evaluate and retrieve
103-
* @return List of object
104-
*/
105-
protected static List<Object> searchPath(LinStore store, String key, Map<String, String> params, String[] children = []) {
106-
final object = store.load(key)
107-
if (!object) {
108-
throw new FileNotFoundException("Lineage object $key not found")
109-
}
110-
final results = new LinkedList<Object>()
111-
if (children && children.size() > 0) {
112-
treatSubObject(store, key, object, children, params, results)
113-
} else {
114-
treatObject(object, params, results)
115-
}
116-
117-
return results
118-
}
119-
120-
private static void treatSubObject(LinStore store, String key, LinSerializable object, String[] children, Map<String, String> params, LinkedList<Object> results) {
121-
final output = getSubObject(store, key, object, children)
122-
if (!output) {
123-
throw new FileNotFoundException("Lineage object $key#${children.join('.')} not found")
124-
}
125-
treatObject(output, params, results)
126-
}
127-
128-
/**
129-
* Get a metadata sub-object.
130-
*
131-
* @param store Store to retrieve lineage metadata objects.
132-
* @param key Parent metadata key.
133-
* @param object Parent object.
134-
* @param children Array of string in indicating the properties to navigate to get the sub-object.
135-
* @return Sub-object or null in it does not exist.
136-
*/
137-
static Object getSubObject(LinStore store, String key, LinSerializable object, String[] children) {
138-
return navigate(object, children.join('.'))
139-
}
140-
14140
/**
14241
* Evaluates object or the objects in a collection matches a set of parameter-value pairs. It includes in the results collection in case of match.
14342
*
@@ -157,23 +56,6 @@ class LinUtils {
15756
}
15857
}
15958

160-
/**
161-
* Parses a query string and store them in parameter-value Map.
162-
*
163-
* @param queryString URI-like query string. (e.g. param1=value1&param2=value2).
164-
* @return Map containing the parameter-value pairs of the query string.
165-
*/
166-
static Map<String, String> parseQuery(String queryString) {
167-
if( !queryString ) {
168-
return [:]
169-
}
170-
final params = queryString.split('&').collectEntries {
171-
it.split('=').collect { URLDecoder.decode(it, 'UTF-8') }
172-
} as Map<String, String>
173-
new LinPropertyValidator().validateQueryParams(params)
174-
return params
175-
}
176-
17759
/**
17860
* Check if an object fulfill the parameter-value
17961
*

modules/nf-lineage/src/main/nextflow/lineage/cli/LinCommandImpl.groovy

+11-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import nextflow.Session
2727
import nextflow.cli.CmdLineage
2828
import nextflow.config.ConfigMap
2929
import nextflow.dag.MermaidHtmlRenderer
30+
import nextflow.file.FileHelper
3031
import nextflow.lineage.LinHistoryRecord
3132
import nextflow.lineage.LinStore
3233
import nextflow.lineage.LinStoreFactory
@@ -98,13 +99,8 @@ class LinCommandImpl implements CmdLineage.LinCommand {
9899
return
99100
}
100101
try {
101-
def entries = LinUtils.query(store, new URI(args[0]))
102-
if( !entries ) {
103-
println "No entries found for ${args[0]}"
104-
return
105-
}
106-
entries = entries.size() == 1 ? entries[0] : entries
107-
println LinUtils.encodeSearchOutputs(entries, true)
102+
final uri = new URI(args[0])
103+
println FileHelper.asPath(uri).text
108104
} catch (Throwable e) {
109105
println "Error loading ${args[0]} - ${e.message}"
110106
}
@@ -319,9 +315,15 @@ class LinCommandImpl implements CmdLineage.LinCommand {
319315
return
320316
}
321317
try {
322-
println LinUtils.encodeSearchOutputs(store.search(args[0]).keySet().collect {asUriString(it)}, true)
318+
final params = args.inject([:]) { acc, entry ->
319+
final tokens = entry.tokenize('=')
320+
acc[tokens[0]] = tokens[1]
321+
acc
322+
} as Map<String,String>
323+
final results = store.search(params).keySet().collect { asUriString(it) }
324+
println LinUtils.encodeSearchOutputs(results, true)
323325
} catch (Throwable e){
324-
println "Error searching for ${args[0]}. ${e.message}"
326+
println "Error searching for '${args.join(' ')}' -- ${e.message}"
325327
}
326328
}
327329
}

modules/nf-lineage/src/main/nextflow/lineage/fs/LinMetadataPath.groovy

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ import java.nio.file.attribute.FileTime
2929
*/
3030
@CompileStatic
3131
class LinMetadataPath extends LinPath {
32-
private byte[] results
32+
private byte[] bytes
3333
private FileTime creationTime
3434

35-
LinMetadataPath(String resultsObject, FileTime creationTime, LinFileSystem fs, String path, String[] childs) {
36-
super(fs, "${path}${childs ? '#'+ childs.join('.') : ''}")
37-
this.results = resultsObject.getBytes("UTF-8")
35+
LinMetadataPath(String object, FileTime creationTime, LinFileSystem fs, String path, String fragment) {
36+
super(fs, "${path}${fragment ? '#'+fragment : ''}")
37+
this.bytes = object.getBytes("UTF-8")
3838
this.creationTime = creationTime
3939
}
4040

4141
InputStream newInputStream() {
42-
return new ByteArrayInputStream(results)
42+
return new ByteArrayInputStream(bytes)
4343
}
4444

4545
SeekableByteChannel newSeekableByteChannel(){
46-
return new LinMetadataSeekableByteChannel(results)
46+
return new LinMetadataSeekableByteChannel(bytes)
4747
}
4848

4949
<A extends BasicFileAttributes> A readAttributes(Class<A> type){
5050
return (A) new BasicFileAttributes() {
5151
@Override
52-
long size() { return results.length }
52+
long size() { return bytes.length }
5353

5454
@Override
5555
FileTime lastModifiedTime() { return creationTime }

0 commit comments

Comments
 (0)