NineSue commented on code in PR #782:
URL: https://github.com/apache/incubator-graphar/pull/782#discussion_r2474386096


##########
maven-projects/spark/snb-graphar-bridge/src/main/scala/org/apache/graphar/datasources/ldbc/bridge/LdbcStreamingBridge.scala:
##########
@@ -0,0 +1,479 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.graphar.datasources.ldbc.bridge
+
+import ldbc.snb.datagen.util.GeneratorConfiguration
+import org.apache.graphar.datasources.ldbc.model.{
+  ConversionResult,
+  StreamingConversionResult,
+  ValidationResult
+}
+import 
org.apache.graphar.datasources.ldbc.stream.core.{LdbcStreamingIntegrator}
+import org.apache.graphar.datasources.ldbc.stream.model.IntegrationStatistics
+import org.apache.spark.sql.SparkSession
+import org.slf4j.{Logger, LoggerFactory}
+
+import scala.util.Try
+
+/**
+ * LDBC streaming bridge (dedicated to streaming processing)
+ *
+ * Provides complete LDBC streaming processing functionality:
+ *   1. Supports streaming processing mode for complete LDBC dataset 2.
+ *      Standardized configuration and validation 3. GraphAr format output
+ */
+class LdbcStreamingBridge extends StreamingBridgeInterface with Serializable {
+
+  private val logger: Logger =
+    LoggerFactory.getLogger(classOf[LdbcStreamingBridge])
+
+  /**
+   * Unified write method (following GraphAr GraphWriter interface)
+   */
+  override def write(
+      path: String,
+      spark: SparkSession,
+      name: String,
+      vertex_chunk_size: Long,
+      edge_chunk_size: Long,
+      file_type: String
+  ): Try[ConversionResult] = {
+    logger.info(
+      s"LdbcStreamingBridge.write() called with path=$path, name=$name"
+    )
+    logger.info("Using streaming mode for all write operations")
+
+    // Convert to streaming configuration and call streaming processing
+    val streamingConfig = StreamingConfiguration(
+      ldbc_config_path = "ldbc_config.properties",
+      output_path = path,
+      scale_factor = "0.1", // Default scale factor
+      graph_name = name,
+      vertex_chunk_size = vertex_chunk_size,
+      edge_chunk_size = edge_chunk_size,
+      file_type = file_type
+    )
+
+    
writeStreaming(streamingConfig)(spark).map(_.asInstanceOf[ConversionResult])
+  }
+
+  /**
+   * Streaming processing dedicated write method (using new streaming
+   * architecture)
+   */
+  override def writeStreaming(
+      config: StreamingConfiguration
+  )(implicit spark: SparkSession): Try[StreamingConversionResult] = Try {
+
+    logger.info("=== STREAMING MODE (FULL IMPLEMENTATION) ===")
+    logger.info(
+      "Using GraphArActivityOutputStream for true streaming processing"
+    )
+    logger.info(
+      "Supporting complete LDBC entities: Person, Forum, Post, Comment, and 
all relationships"
+    )
+
+    val startTime = System.currentTimeMillis()
+
+    // Create streaming integrator
+    val streamingIntegrator = new LdbcStreamingIntegrator(
+      output_path = config.output_path,
+      graph_name = config.graph_name,
+      vertex_chunk_size = config.vertex_chunk_size,
+      edge_chunk_size = config.edge_chunk_size,
+      file_type = config.file_type
+    )
+
+    try {
+      // Create LDBC configuration
+      val ldbcConfig = createLdbcConfiguration(config)
+
+      // Execute streaming conversion
+      val conversionResult =
+        streamingIntegrator.executeStreamingConversion(ldbcConfig)
+
+      conversionResult match {
+        case scala.util.Success(result) =>
+          logger.info(
+            s"✓ Streaming conversion completed: 
${result.processingDurationMs}ms"
+          )
+          logger.info(
+            s"✓ Supported entity types: 
${streamingIntegrator.getSupportedEntityTypes().mkString(", ")}"
+          )
+          logger.info(
+            s"✓ Processed entities: 
${result.integrationStatistics.processedEntities.mkString(", ")}"
+          )
+          logger.info(
+            s"✓ Total records: ${result.integrationStatistics.totalRecords}"
+          )
+          logger.info(
+            "✓ Streaming conversion completed, real LDBC data generation 
successful"
+          )
+          result
+
+        case scala.util.Failure(exception) =>
+          logger.error("✗ Streaming conversion failed", exception)
+          throw exception // Directly throw exception, no fallback
+      }
+
+    } finally {
+      streamingIntegrator.cleanup()
+    }
+  }
+
+  /**
+   * Create LDBC configuration
+   */
+  private def createLdbcConfiguration(
+      config: StreamingConfiguration
+  ): GeneratorConfiguration = {
+    val ldbcConfig = new GeneratorConfiguration(
+      new java.util.HashMap[String, String]()
+    )
+
+    // *** Complete LDBC configuration based on params_default.ini ***
+
+    // Basic probability parameters
+    ldbcConfig.map.put("generator.baseProbCorrelated", "0.95")

Review Comment:
   Okay, I understand... I'll optimize it in the future. Thank you!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to