Class SparkSql

java.lang.Object
com.hw.langchain.utilities.spark.sql.SparkSql

public class SparkSql extends Object
Author:
HamaWhite
  • Constructor Details

    • SparkSql

      public SparkSql()
  • Method Details

    • init

      public SparkSql init()
    • fromUri

      public static SparkSql fromUri(String databaseUri)
      Creating a remote Spark Session via Spark connect.
      Parameters:
      databaseUri - The database URI, e.g., "sc://localhost:15002".
      Returns:
      A SparkSql instance.
    • getUsableTableNames

      public Set<String> getUsableTableNames()
      Get names of tables available.
    • getTableInfo

      public String getTableInfo(Set<String> tableNames)
    • getSampleSparkRows

      public String getSampleSparkRows(String table)
    • run

      public String run(String command, FetchType fetchType)
    • getTableInfoNoThrow

      public String getTableInfoNoThrow(Set<String> tableNames)
      Get information about specified tables.

      Follows best practices as specified in: Rajkumar et al, 2022

      If `sample_rows_in_table_info`, the specified number of sample rows will be appended to each table description. This can increase performance as demonstrated in the paper.

    • runNoThrow

      public String runNoThrow(String command, FetchType fetch)
      Execute a SQL command and return a string representing the results.

      If the statement returns rows, a string of the results is returned. If the statement returns no rows, an empty string is returned. If the statement throws an error, the error message is returned.

    • runNoThrow

      public String runNoThrow(String command)