Selections
Selections are virtual views on the project graph and other data which allow to work with transformed intermediate data structures.
A single selection is basically a dynamic volatile set of key value pairs which doesn't have to reflect any persistent structures.
Selections can be combined and transformed in many ways. They are also the basis for many statistical analyses.
A single selection is basically a dynamic volatile set of key value pairs which doesn't have to reflect any persistent structures.
Selections can be combined and transformed in many ways. They are also the basis for many statistical analyses.
Selecting data
Selecting specific values:
Selecting attributes from elements:
Selecting rows from tables (rows as selections and columns as keys):
Selecting columns from tables (columns as selections and rows as keys):
Selecting specific value
var selections1 = diafunc.select()
.append("key1", "value1")
.append("key1", "value2")
.append("key1", "value3");
selections1 = selections1
.put("key2", "value4")
.put("key3", "value5");
var selections2 = diafunc.select()
.append()
.put("key1", "value1")
.put("key2", "value2")
.put("key3", "value3")
.build()
.append()
.put("key1", "value4")
.put("key2", "value5")
.put("key3", "value6")
.build();
Selecting attributes from elements:
Selecting attributes
var selections1 = elements.attributes().select();
var selections2 = elements.attribute("attributeName").select();
var attributeNames = diafunc.create().tuple()
.add("attributeName1")
.add("attributeName2")
.add("attributeName3");
var selections3 = elements.attributes(attributeNames).select();
Selecting rows from tables (rows as selections and columns as keys):
Selecting rows
var selections = table.selectRows();Selecting columns from tables (columns as selections and rows as keys):
Selecting columns
var selections = table.selectColumns();Joins
Selections can be joined together, corresponding to a join operation in relational algebra.
Cross Join
A Cross Join combines each selection of the left set with each selection of the right set.
Cross Join
var resultingSelections = leftSelections.join(rightSelections);Inner Join
An Inner Join combines each selection of the left set with each selection of the right set where the values of the given keys match. Only matching combinations are resulting.
Inner Join
var resultingSelections = leftSelections.join(rightSelections, "key");Natural Join
A Natural Join combines each selection of the left set with each selection of the right set where the values of all keys match which are available in both selections.
Natural Join
var resultingSelections = leftSelections.naturalJoin(rightSelections);Left Outer Join
A Left Outer Join combines each selection of the left set with each selection of the right set where the values of the given keys match. Also non-matching selections of the left set are resulting.
Left Outer Join
var resultingSelections = leftSelections.leftJoin(rightSelections, "key");Right Outer Join
A Right Outer Join combines each selection of the left set with each selection of the right set where the values of the given keys match. Also non-matching selections of the right set are resulting.
Right Outer Join
var resultingSelections = leftSelections.rightJoin(rightSelections, "key");Mappings
Selections can be mapped to derived selections. Mapping values maps the values for a given key.
Map values for key
var mappedSelections = originalSelections.mapValues("key", value -> value.toString() + "_mapped");Filtering
Selection can be filtered in many ways.
Filtering Selections
var filteredSelections = originalSelections.equal("key", "value");
filteredSelections = originalSelections.greaterThan("key", 10);
filteredSelections = originalSelections.lessThan("key", 20);
filteredSelections = originalSelections.like("key", "a.*b[0-9]+");
Like any bulk, a bulk of selections can also be filtered with a custom predicate, for example by a minimum value for a specific key:
Filtering with a predicate
var filteredSelections = selections.filter(selection -> selection.key("key").number() >= 42);Sorting
Selections can be sorted in any way.
Sorting Selections
var sortedSelections = originalSelections.sort().key("key").ascending().nullsFirst().sorted(); Alternatively, a bulk of selections can be sorted by a custom key extractor:
Sorting with a key extractor
var sortedSelections = selections.sort(selection -> selection.key("key").number());