Spark via JDBC
SQL can be issued against Kinetica through the Spark JDBC interface. This not only allows for data ingest/egress, but provides access to native Kinetica functions in queries, including geospatial operations. See Connecting via JDBC for obtaining the JDBC driver.JDBC queries will not be partitioned, as they were when using the
Egress Processor of the Legacy Spark Connector.
Spark Egress
The following example shows how to execute queries against Kinetica. It will use JDBC as the read format, require the Kinetica JDBC driver to be accessible and load it, and allow the specified query to run. The result of the query will be loaded into aDataFrame and the schema and result set will be output to
the console.
This example makes use of the NYC taxi trip table, which can be loaded using
GAdmin from the Demo Data page, under Cluster > Demo.
-
Launch Spark Shell:
-
Configure JDBC for source database and specify query for map key
dbtable; be sure to provide an appropriate value forurlfor the target system, as well asusername&password, if the database is configured to require authentication.If connecting over SSL, see JDBC Secure Connections for the modified URL to use. -
Read queried data from Kinetica into
DataFrame: -
Output
DataFrameschema for query: -
Verify output:
-
Output query result set:
-
Verify output:
Spark Ingest
The following example shows how to ingest data into Kinetica. It will use JDBC as the write format, require the Kinetica JDBC driver to be accessible and load it, and ingest the givenDataFrame into a new table.
This example makes use of the DataFrame populated in the Spark Egress
section, referencing it as df.
- Run the Spark Egress example.
-
Update the options map, specifying the table to ingest into for map key
dbtable. -
Write data from
DataFrameinto Kinetica: -
Verify the ingestion into the
demo.nyctaxi_copytable using GAdmin or Workbench.
Spark Logging
Logging of Kinetica JDBC operations can be configured via the JDBC URL, by adding aLogLevel parameter to the end of the URL. Valid log levels can be
found under JDBC Client Parameters.
For instance, to enable DEBUG logging:
DEBUG logging, without having to modify
the JDBC URL:
Mapping Spark to Kinetica
Some Spark data types and functions may need custom mappings to Kinetica. The following dialect snippet is a custom mapping, which maps:- Spark’s CLOB/VARCHAR types to the Kinetica
VARCHARtype - Spark’s BLOB type to the Kinetica
BLOBtype - Spark’s boolean type to the Kinetica
TINYINTtype - The truncate command (which does
DROP/CREATE, by default) to Kinetica’sTRUNCATE TABLEcommand