PolarDB is the next-generation cloud-native distributed relational database that is developed by Alibaba Cloud. The Ganos spatial-temporal engine developed by Alibaba Cloud provides various data types, functions, and stored procedures for PolarDB to efficiently store, index, query, analyze, and compute spatial-temporal data. DLA Ganos is compatible with the data access interface of PolarDB Ganos. This allows you to directly load vector data from PolarDB Ganos.

This topic describes how to use DLA Ganos to load vector data from PolarDB Ganos. In this topic, an automatic identification system (AIS) dataset of global vessel trajectories is used as vector data.

  1. Initialize the Spark environment.
    // Initialize a Spark session.
    val spark = SparkSession.builder
        .appName("Simple Application")
        .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
        .config("spark.sql.crossJoin.enabled", "true")
        .config("spark.kryo.registrator", classOf[GanosSparkKryoRegistrator].getName)
    import spark.implicits. _
    // Load the JTS package for the Spark session to process spatio-temporal data.
    val sc = spark.sparkContext
  2. Load data.
    1. Load data in the Spark format.
      // Configure connection parameters.
        val dsParams: JMap[String, String] = Map(
          "host" -> "URL of the PolarDB database",
          "polardb.ganos" -> "true",
          "port"->"Port of the PolarDB database",
          "database"->"Name of the PolarDB database",
      // Load the AIS dataset.
      df = spark.read.format("ganos-geometry")
            .option("ganos.feature", "AIS")
    2. Load data by calling the Spark DataFrame API.
      val layer=spark.read.ganos.polardbGeometry(dsParams)
  3. View the results.