java.lang.Object
org.odpi.openmetadata.adapters.connectors.duckdb.utilities.DuckDBUtils

public class DuckDBUtils extends Object
DuckDBUtils provides simple functions to work with DuckDB database paths and JDBC connection strings. DuckDB is embedded - there is no server tier and so, unlike the other database connector suites, there is no need to rewrite a server-level URL into a database-level URL. A DuckDB JDBC URL is simply the "jdbc:duckdb:" prefix followed by either the path to the database file, or the literal value ":memory:" for an in-memory session.
  • Field Details

    • IN_MEMORY_DATABASE

      public static final String IN_MEMORY_DATABASE
      The configuration value that requests an in-memory (non-persistent) DuckDB database.
      See Also:
  • Constructor Details

    • DuckDBUtils

      public DuckDBUtils()
  • Method Details

    • isInMemoryDatabase

      public static boolean isInMemoryDatabase(String databasePath)
      Return whether the supplied database path represents an in-memory DuckDB session rather than a file on disk.
      Parameters:
      databasePath - configured value of the database path/name
      Returns:
      boolean flag
    • getDatabaseURL

      public static String getDatabaseURL(String databasePath)
      Build the JDBC connection string for a DuckDB database.
      Parameters:
      databasePath - path to the ".duckdb" file on disk, or ":memory:"/null for an in-memory session
      Returns:
      connection string
    • getAttachStatements

      public static List<String> getAttachStatements(Map<String,Object> configurationProperties)
      Extract the ATTACH_STATEMENTS configuration property as a list of complete SQL statements. This deliberately does NOT use the generic comma-separated-list configuration property helper used elsewhere in this connector suite (eg for excludeDatabaseList) - a realistic ATTACH statement almost always contains at least one comma itself (for example, inside its "(TYPE POSTGRES, READ_ONLY)" options list), so splitting the raw value on every comma would corrupt the statements. Instead, when the configuration property has been supplied as a JSON array (the norm - it arrives already deserialized as a List), each element is used as-is, one statement per list entry. A configuration property supplied as a single string is treated as one complete statement.
      Parameters:
      configurationProperties - configuration properties for this survey/catalog target
      Returns:
      list of statements - never null, may be empty
    • runAttachStatements

      public static void runAttachStatements(Connection connection, List<String> attachStatements, AuditLog auditLog, String connectorName, String databaseName)
      Run the configured ATTACH_STATEMENTS on a freshly-opened DuckDB connection. DuckDB does not persist ATTACH-ed data sources in the database file between sessions, so a survey or catalog connector's own connection needs to re-issue the original ATTACH (and any INSTALL/LOAD) statements itself before it queries duckdb_databases() - otherwise it will never see any of the database's federation relationships. Each statement is run independently and defensively: one failing statement (for example, an extension that is already installed, or a stale/unreachable attachment) must not prevent the rest of the statements from running, or the rest of the survey/catalog pass from completing.
      Parameters:
      connection - freshly-opened connection to the DuckDB database
      attachStatements - SQL statements to run, in order - may be null or empty
      auditLog - logging destination
      connectorName - name of the calling connector - used in audit log messages
      databaseName - name/path of the DuckDB database - used only in audit log messages