> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute an arbitrary Scala script

> Results of computation can be returned to the caller as a part of the job status, by assigning the result in the script to a variable called `result`. The `result` is flat strings and not JSON. You can use `sqlContext.read.json(…​)` to read this file as a `DataFrame`.



## OpenAPI

````yaml /api-reference/4.2/service-spark.json post /spark/script
openapi: 3.0.0
info:
  version: 4.2.6-rc1
  title: Fusion Service spark
servers:
  - url: /api/apollo/
security: []
tags:
  - name: spark
paths:
  /spark/script:
    post:
      tags:
        - 4.2 Spark API
      summary: Execute an arbitrary Scala script
      description: >-
        Results of computation can be returned to the caller as a part of the
        job status, by assigning the result in the script to a variable called
        `result`. The `result` is flat strings and not JSON. You can use
        `sqlContext.read.json(…​)` to read this file as a `DataFrame`.
      operationId: startUndefinedScriptedJob
      parameters:
        - name: sync
          in: query
          description: >-
            When true, run the job synchronously; the request will not return
            until the job is complete
          required: false
          schema:
            type: boolean
        - name: rows
          in: query
          description: Page size for reading out of Solr
          required: false
          schema:
            type: integer
            format: int32
        - name: Content-Type
          in: header
          description: The media type of the entity body
          required: false
          schema:
            type: string
            default: application/octet-stream
      requestBody:
        content:
          '*/*':
            schema:
              type: array
              items:
                type: string
                format: byte
        description: Scala script
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SparkJobStatus'
components:
  schemas:
    SparkJobStatus:
      type: object
      properties:
        state:
          type: string
          readOnly: true
          enum:
            - unknown
            - idle
            - starting
            - running
            - finishing
            - cancelling
            - finished
            - cancelled
            - error
            - skipped
        jobId:
          type: string
          readOnly: true
        jobConfig:
          $ref: '#/components/schemas/SparkJobConfig'
        hostname:
          type: string
          readOnly: true
        result:
          $ref: '#/components/schemas/SparkJobResult'
        startTime:
          type: string
          readOnly: true
        endTime:
          type: string
          readOnly: true
        duration:
          type: integer
          format: int64
          readOnly: true
    SparkJobConfig:
      type: object
      properties:
        id:
          type: string
          readOnly: true
    SparkJobResult:
      type: object
      properties:
        jobConfigId:
          type: string
          readOnly: true
        jobRunId:
          type: string
          readOnly: true
        docsWritten:
          type: integer
          format: int64
          readOnly: true
        exception:
          $ref: '#/components/schemas/JobExecutionError'
    JobExecutionError:
      type: object
      discriminator:
        propertyName: type
      properties:
        job:
          $ref: '#/components/schemas/FusionResource'
        jobRunId:
          type: string
          readOnly: true
        httpStatusCode:
          type: integer
          format: int32
          readOnly: true
        error:
          type: string
          readOnly: true
        message:
          type: string
          readOnly: true
        details:
          type: string
          readOnly: true
        cause:
          $ref: '#/components/schemas/Throwable'
        stackTrace:
          type: array
          items:
            $ref: '#/components/schemas/StackTraceElement'
        localizedMessage:
          type: string
        suppressed:
          type: array
          items:
            $ref: '#/components/schemas/Throwable'
        httpStatusMessage:
          type: string
          readOnly: true
        class:
          type: string
          readOnly: true
        requestId:
          type: string
          readOnly: true
    FusionResource:
      type: object
      properties:
        type:
          type: string
          enum:
            - APPKIT_APP
            - WEBAPP_ADMIN_APP
            - APP
            - COLLECTION
            - INDEX_PIPELINE
            - INDEX_STAGE
            - QUERY_STAGE
            - QUERY_PIPELINE
            - INDEX_PROFILE
            - QUERY_PROFILE
            - BLOB
            - PARSER
            - DATASOURCE
            - TASK
            - SCHEDULE
            - SEARCH_CLUSTER
            - EXPERIMENT
            - SPARK_JOB
            - GROUP
            - CUSTOM_RULE_TYPE
            - TYPE
            - RESOURCE
            - 'NULL'
        id:
          type: string
        canonicalName:
          type: string
        uri:
          type: string
          format: uri
    Throwable:
      type: object
      properties:
        cause:
          $ref: '#/components/schemas/Throwable'
        stackTrace:
          type: array
          items:
            $ref: '#/components/schemas/StackTraceElement'
        message:
          type: string
        localizedMessage:
          type: string
        suppressed:
          type: array
          items:
            $ref: '#/components/schemas/Throwable'
    StackTraceElement:
      type: object
      properties:
        methodName:
          type: string
        fileName:
          type: string
        lineNumber:
          type: integer
          format: int32
        className:
          type: string
        nativeMethod:
          type: boolean
          default: false

````