Search in sources :

Example 46 with ResourcePath

use of au.csiro.pathling.fhirpath.ResourcePath in project pathling by aehrc.

the class PathTraversalOperator method getValueField.

@Nonnull
private static Column getValueField(@Nonnull final NonLiteralPath path, @Nonnull final String fieldName) {
    // If the input path is a ResourcePath, we look for a bare column. Otherwise, we will need to
    // extract it from a struct.
    final Column field;
    if (path instanceof ResourcePath) {
        final ResourcePath resourcePath = (ResourcePath) path;
        // When the value column of the ResourcePath is null, the path traversal results in null. This
        // can happen when attempting to do a path traversal on the result of a function like when.
        field = when(resourcePath.getValueColumn().isNull(), lit(null)).otherwise(resourcePath.getElementColumn(fieldName));
    } else {
        field = path.getValueColumn().getField(fieldName);
    }
    return field;
}
Also used : ResourcePath(au.csiro.pathling.fhirpath.ResourcePath) Column(org.apache.spark.sql.Column) Nonnull(javax.annotation.Nonnull)

Aggregations

ResourcePath (au.csiro.pathling.fhirpath.ResourcePath)46 Test (org.junit.jupiter.api.Test)32 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)28 Row (org.apache.spark.sql.Row)26 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)25 FhirPath (au.csiro.pathling.fhirpath.FhirPath)23 ResourcePathBuilder (au.csiro.pathling.test.builders.ResourcePathBuilder)23 ElementPath (au.csiro.pathling.fhirpath.element.ElementPath)16 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)16 ResourceDatasetBuilder (au.csiro.pathling.test.builders.ResourceDatasetBuilder)16 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)15 InvalidUserInputError (au.csiro.pathling.errors.InvalidUserInputError)14 Column (org.apache.spark.sql.Column)14 UntypedResourcePath (au.csiro.pathling.fhirpath.UntypedResourcePath)11 Nonnull (javax.annotation.Nonnull)11 NonLiteralPath (au.csiro.pathling.fhirpath.NonLiteralPath)8 UntypedResourcePathBuilder (au.csiro.pathling.test.builders.UntypedResourcePathBuilder)8 ElementDefinition (au.csiro.pathling.fhirpath.element.ElementDefinition)5 StringLiteralPath (au.csiro.pathling.fhirpath.literal.StringLiteralPath)4