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)
        .getOrCreate()
    import spark.implicits. _
    
    // Load the JTS package for the Spark session to process spatio-temporal data.
    spark.withJTS 
    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",
          "dbtype"->"polardb", 
          "port"->"Port of the PolarDB database",
          "schema"->"public",
          "database"->"Name of the PolarDB database",
          "user"->"Username",
          "passwd"->"Password")
      
      // Load the AIS dataset.
      df = spark.read.format("ganos-geometry")
            .options(dsParams)
            .option("ganos.feature", "AIS")
            .load()
      df.show
    2. Load data by calling the Spark DataFrame API.
      val layer=spark.read.ganos.polardbGeometry(dsParams)
      layer.show
  3. View the results.