Submit a SQL query and return results.
post
/spatialviewer/api/v1/spark/sqlQuery
Submit a SQL query to Spark and return results.
Request
Supported Media Types
- application/json
Query Parameters
-
allStringTypeColumns: boolean
if true all the output columns except the geometry will be double quotedDefault Value:
false
-
analysisName: string
The name of the analysis. This parameter is required when outputAsAnalysis is set to true
-
asynchronous: boolean
if true the operation is runned asynchronously.Default Value:
false
-
fullResult: boolean
if false and asynchronously is false then the response contains the location of the results in HDFS and not the actual results.Default Value:
true
-
outputAsAnalysis: boolean
if true the index will be added to the analysis results of the SpatialViewer UIDefault Value:
false
-
resultAsGeoJson: boolean
if true the service returns the response as GeoJSON that can be used as data source for the Map API to display the results on map. The geometry has to be returned in a field named geometry. Example: SELECT geometry, friends_count...Default Value:
false
SQL query details
Root Schema : SQLQueryInfo
Type:
Show Source
object
-
jarWithNeededClasses(optional):
string
jar name with the user-defined classes like custom RecordInfoProvider or InputFormat. If the InputFormat class or the RecordInfoProvider class is not in the API, or in the hadoop API classes, then a jar with the user-defined classes must be provided. To be able to use this jar the user must add it in the /opt/oracle/oracle-spatial-graph/spatial/web-server/spatialviewer/WEB-INF/lib directory and restart the server. Optional property that can be set if useIndex is false.Example:
myjar.jar
-
outputPath(optional):
string
The job output path. Specify this property if asynchronous is true.Example:
/user/oracle/spatialviewer/SQLQueryResult
-
query(optional):
string
The SQL query.Example:
SELECT geometry, friends_count, location, followers_count FROM tweets WHERE ST_Contains( ST_Polygon('{"type": "Polygon","coordinates": [[[-106, 25], [-106, 30], [-104, 30], [-104, 25], [-106, 25]]]}', 8307) , ST_Point(geometry, 8307) , 0.05) and followers_count > 50
-
stringTypeColumns(optional):
string
Index of the output columns that will be double quoted. The index are comma separated. The first index is 0.Example:
2,3
-
tables(optional):
array tables
Nested Schema : Table
Type:
Show Source
object
-
columnNames(optional):
array columnNames
The extra fields of the RecordInfoProvider to include in the columns of the table. Note that the column geometry will always be the first column and will contain the geometry in GeoJSON format.
-
dataPath(optional):
string
Path of the file or files in HDFS.Example:
/user/oracle/spatialviewer/tweetsJune.json
-
inputFormatClass(optional):
string
The input format class. Optional property. If the input format class is not specified then the SparkContext's textFile is used.Example:
oracle.spatial.hadoop.vector.geojson.mapred.GeoJsonInputFormat
-
keyClass(optional):
string
Class of the input format keys. This property is required if an input format is defined.Example:
org.apache.hadoop.io.LongWritable
-
name(optional):
string
Table name.Example:
tweets
-
recordInfoProviderClass(optional):
string
The class that provides the spatial information.Example:
oracle.spatial.spark.vector.recordinfoprovider.GeoJsonRecordInfoProvider
-
srid(optional):
integer(int32)
SRID of the geometries.Example:
8307
-
valueClass(optional):
string
Class of the input format values. This property is required if an input format is defined.Example:
org.apache.hadoop.io.Text
Nested Schema : columnNames
Type:
array
The extra fields of the RecordInfoProvider to include in the columns of the table. Note that the column geometry will always be the first column and will contain the geometry in GeoJSON format.
Show Source
-
Array of:
Example:
friends_count location followers_count
Example:
[
"friends_count",
"location",
"followers_count"
]
Response
Supported Media Types
- application/json
200 Response
successful request. If fullResult is false then the response contains the location of the results in HDFS.
Nested Schema : SparkSQLRecordExample
Type:
Show Source
object
-
followers_count(optional):
number
Example:
13
-
friends_count(optional):
number
Example:
121
-
geometry(optional):
object geometry
-
location(optional):
string
Example:
Madrid
Nested Schema : geometry
Type:
object
Example:
{
"type":"Point",
"coordinates":[
-3.6853,
40.40197
]
}
202 Response
accepted asynchronous request
Root Schema : AsyncSparkSQLJobResponse
Type:
Show Source
object
-
o:successCode(optional):
string
The success code.Example:
SV-05013
-
response(optional):
string
The response contains the location of the resource manager web application URL to track the job (see in the configuration the Hadoop parameter yarn.resourcemanager.webapp.address).Example:
http://resource.manager.webapp:8088
-
status(optional):
string
success or errorExample:
success
-
title(optional):
string
Service title.Example:
Execute Spark SQL query.
Examples
The following example shows how to execute a Spark SQL Query by submitting a POST request on the REST resource using cURL.
curl -v -X POST "http://localhost:8045/spatialviewer/api/v1/spark/sqlQuery?fullResult=true" -H "accept: application/json" -H "content-type: application/json" -d "{ \"query\": \"SELECT geometry, friends_count, location, followers_count FROM tweets WHERE ST_Contains( ST_Polygon('{\\\"type\\\": \\\"Polygon\\\",\\\"coordinates\\\": [[[-106, 25], [-106, 30], [-104, 30], [-104, 25], [-106, 25]]]}', 8307) , ST_Point(geometry, 8307) , 0.05) and followers_count > 50\", \"stringTypeColumns\": \"2,3\", \"tables\": [ { \"name\": \"tweets\", \"columnNames\": [ \"friends_count\", \"location\", \"followers_count\" ], \"srid\": 8307, \"dataPath\": \"/user/oracle/tweets.json\", \"inputFormatClass\": \"oracle.spatial.hadoop.vector.geojson.mapred.GeoJsonInputFormat\", \"keyClass\": \"org.apache.hadoop.io.LongWritable\", \"valueClass\": \"org.apache.hadoop.io.Text\", \"recordInfoProviderClass\": \"oracle.spatial.spark.vector.recordinfoprovider.GeoJsonRecordInfoProvider\" } ]}"
Example of Response Header
The following shows an example of the response header.
HTTP/1.1 200 OK Date: Wed, 15 Nov 2017 17:50:38 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, Accept Transfer-Encoding: chunked Content-Type: application/json
Example of Response Body
The following example shows the contents of the response body in JSON format, including one record:
{"items":[{"geometry":{"type":"Point","coordinates":[-104.41002,29.5404]},"friends_count":72,"location":"Chihuahua","followers_count":"94"}]}