本文整理匯總了Java中org.apache.spark.sql.Dataset.map方法的典型用法代碼示例。如果您正苦於以下問題:Java Dataset.map方法的具體用法?Java Dataset.map怎麽用?Java Dataset.map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.spark.sql.Dataset
的用法示例。
在下文中一共展示了Dataset.map方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toJson
import org.apache.spark.sql.Dataset; //導入方法依賴的package包/類
/**
* Converts a set of FHIR resources to JSON.
*
* @param dataset a dataset containing FHIR resources
* @param resourceType the FHIR resource type
* @return a dataset of JSON strings for the FHIR resources
*/
public static Dataset<String> toJson(Dataset<?> dataset, String resourceType) {
Dataset<IBaseResource> resourceDataset =
dataset.as(FhirEncoders.forStu3()
.getOrCreate()
.of(resourceType));
return resourceDataset.map(new ToJson(), Encoders.STRING());
}
示例2: withConceptMaps
import org.apache.spark.sql.Dataset; //導入方法依賴的package包/類
/**
* Returns a new ConceptMaps instance that includes the given maps.
*
* @param conceptMaps concept maps to add to the returned collection.
* @return a new ConceptMaps instance with the values added.
*/
public ConceptMaps withConceptMaps(Dataset<ConceptMap> conceptMaps) {
Dataset<UrlAndVersion> newMembers = getUrlAndVersions(conceptMaps);
if (hasDuplicateUrlAndVersions(newMembers) || conceptMaps.count() != newMembers.count()) {
throw new IllegalArgumentException(
"Cannot add concept maps having duplicate conceptMapUri and conceptMapVersion");
}
// Remove the concept contents for persistence. This is most easily done in the ConceptMap
// object by setting the group to an empty list.
Dataset<ConceptMap> withoutConcepts = conceptMaps
.map((MapFunction<ConceptMap,ConceptMap>) conceptMap -> {
// Remove the elements rather than the groups to preserved the
// "unmapped" structure in a group that can refer to other
// concept maps.
ConceptMap withoutElements = conceptMap.copy();
List<ConceptMapGroupComponent> updatedGroups = new ArrayList<>();
for (ConceptMapGroupComponent group: withoutElements.getGroup()) {
group.setElement(new ArrayList<>());
updatedGroups.add(group);
}
withoutElements.setGroup(updatedGroups);
return withoutElements;
}, CONCEPT_MAP_ENCODER);
Dataset<Mapping> newMappings = conceptMaps.flatMap(ConceptMaps::expandMappingsIterator,
MAPPING_ENCODER);
return withConceptMaps(withoutConcepts, newMappings);
}
示例3: withValueSets
import org.apache.spark.sql.Dataset; //導入方法依賴的package包/類
/**
* Returns a new ValueSets instance that includes the given value sets.
*
* @param valueSets the value sets to add to the returned collection.
* @return a new ValueSets instance with the added value sets.
*/
public ValueSets withValueSets(Dataset<ValueSet> valueSets) {
Dataset<UrlAndVersion> newMembers = getUrlAndVersions(valueSets);
// Ensure that there are no duplicates among the value sets
if (hasDuplicateUrlAndVersions(newMembers) || valueSets.count() != newMembers.count()) {
throw new IllegalArgumentException(
"Cannot add value sets having duplicate valueSetUri and valueSetVersion");
}
// The value set concepts will be stored in the values table for persistence, so we remove
// them from the individual value sets. This can be done most easily by setting concepts to an
// empty list.
Dataset<ValueSet> withoutConcepts = valueSets.map((MapFunction<ValueSet,ValueSet>) valueSet -> {
ValueSet valueSetWithoutConcepts = valueSet.copy();
List<ConceptSetComponent> updatedInclusions = new ArrayList<>();
for (ConceptSetComponent inclusion: valueSet.getCompose().getInclude()) {
ConceptSetComponent inclusionWithoutConcepts = inclusion.copy();
inclusionWithoutConcepts.setConcept(new ArrayList<>());
updatedInclusions.add(inclusionWithoutConcepts);
}
valueSetWithoutConcepts.getCompose().setInclude(updatedInclusions);
return valueSetWithoutConcepts;
}, VALUE_SET_ENCODER);
Dataset<Value> newValues = valueSets.flatMap(ValueSets::expandValuesIterator, VALUE_ENCODER);
return withValueSets(withoutConcepts, newValues);
}