How to Load Data from Apache Iceberg to AWS Neptune Using Apache Spark Without AWS Services? Is It Scalable?

I am currently working on a project where I need to load data from an Apache Iceberg table into an AWS Neptune graph database. I want to perform this task using an Apache Spark, but I prefer not to use any additional AWS services such as AWS DMS for this integration. The volume of data that I am talking about is 400GB initially after that every day around 15GB incremental data.

Here’s a brief overview of my setup and requirements:

  • Data Source: Apache Iceberg table
  • Target Database: AWS Neptune
  • Intermediate Processing: Apache Spark

My Current Approach

I have written a Spark program in Scala that reads data from the Iceberg table and uses the Gremlin API to insert the data into Neptune. Here is the simplified version of the code:

import org.apache.spark.sql.{SparkSession, Row, DataFrame}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.{StringType, StructField, StructType}
import org.apache.iceberg.spark.Spark3Util
import org.apache.tinkerpop.gremlin.driver.{Client, Cluster}
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph
import org.apache.tinkerpop.gremlin.structure.Graph
import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider}
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.neptune.NeptuneClient

object NeptuneSparkApp {

  def main(args: Array[String]): Unit = {
    // Initialize Spark session
    val spark = SparkSession.builder
      .appName("NeptuneSparkApp")
      .config("spark.sql.extensions", "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")
      .config("spark.sql.catalog.spark_catalog", "org.apache.iceberg.spark.SparkSessionCatalog")
      .config("spark.sql.catalog.spark_catalog.type", "hive")
      .config("spark.sql.catalog.spark_catalog.uri", "thrift://localhost:9083") // Update with your Hive Metastore URI
      .getOrCreate()

    // Define AWS Neptune endpoint and credentials
    val neptuneEndpoint = "your-neptune-endpoint:8182"
    val neptuneRegion = "your-region"
    val awsAccessKeyId = "your-access-key-id"
    val awsSecretAccessKey = "your-secret-access-key"

    // Initialize Neptune Client
    val credentials = AwsBasicCredentials.create(awsAccessKeyId, awsSecretAccessKey)
    val neptuneClient = NeptuneClient.builder()
      .region(Region.of(neptuneRegion))
      .credentialsProvider(StaticCredentialsProvider.create(credentials))
      .build()

    // Connect to Neptune
    val cluster = Cluster.build(neptuneEndpoint).create()
    val client = cluster.connect()
    val graph = RemoteGraph.open(client, "g")

    // Read data from Iceberg table
    val icebergTable: DataFrame = spark.read
      .format("iceberg")
      .load("spark_catalog.db.table_name") // Update with your Iceberg table path

    // Function to insert data into Neptune
    def insertDataToNeptune(row: Row): Unit = {
      val g = graph.traversal()
      g.addV("person")
        .property("id", row.getAs[String]("id"))
        .property("name", row.getAs[String]("name"))
        .property("age", row.getAs[Int]("age"))
        .next()
    }

    // Apply the function to each row in the DataFrame
    icebergTable.collect().foreach(insertDataToNeptune)

    // Close the connection
    client.close()
    cluster.close()

    // Stop the Spark session
    spark.stop()
  }
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật