Class DatasourceSchemaUtils

java.lang.Object
com.inductiveautomation.ignition.designer.ai.datasource.DatasourceSchemaUtils

public class DatasourceSchemaUtils extends Object
  • Method Details

    • longestMatch

      public static @Nullable String longestMatch(List<String> candidates, String query)
      Longest entry in candidates that query continues with a ., or null when the query has not named one yet. When several candidates match, the longest wins.

      Resolving a query against the names that actually exist is what lets those names contain dots themselves: a schema-qualified table arrives already flattened to schema.table, so the separator alone cannot tell a qualified name from a name followed by a child.

    • datasourcesAsync

      public static CompletableFuture<List<DatasourceRpc.DatasourceMetaInfo>> datasourcesAsync()
      Fetches all datasources currently on the gateway. Resolves to an empty list if the fetch fails.
    • tablesAsync

      public static CompletableFuture<List<String>> tablesAsync(String datasource)
      Fetches all tables in datasource. Resolves to an empty list if the fetch fails.
      Parameters:
      datasource - the name of the datasource to fetch tables from.
    • columnsAsync

      public static CompletableFuture<List<DatasourceRpc.ColumnMetaInfo>> columnsAsync(String datasource, String tableName)
      Fetches all columns of tableName in datasource. Resolves to an empty list if the fetch fails.
      Parameters:
      datasource - the name of the datasource containing the table.
      tableName - the name of the table to fetch columns from.
    • renderDatasources

      public static List<PromptAssist.Option> renderDatasources(List<DatasourceRpc.DatasourceMetaInfo> datasources, String prefix)
      Filters datasources to names containing prefix (case-insensitive) and renders each match as an PromptAssist.Option for the datasource prompt assist popup. Datasources with a blank name are skipped.
      Parameters:
      datasources - the datasources to filter and render.
      prefix - the case-insensitive substring to match against each datasource's name.
      Returns:
      one option per matching datasource, in datasources order.
    • renderTables

      public static List<PromptAssist.Option> renderTables(String datasource, List<String> tables, String prefix)
      Filters tables to names starting with prefix (case-insensitive) and renders each match as an PromptAssist.Option for the table prompt assist popup. Tables with a blank name are skipped.
      Parameters:
      datasource - the name of the datasource to render tables for.
      tables - the list of tables to filter and render.
      prefix - the case-insensitive prefix to match against each table's name.
      Returns:
      one option per matching table, in tables order.
    • renderColumns

      public static List<PromptAssist.Option> renderColumns(String datasource, String tableName, List<DatasourceRpc.ColumnMetaInfo> columns, String filter)
      Filters columns to names starting with filter (case-insensitive) and renders each match as an PromptAssist.Option for the column prompt assist popup. Columns with a blank name are skipped.
      Parameters:
      datasource - the name of the datasource to render columns for.
      tableName - the name of the table to render columns for.
      columns - the list of columns to filter and render.
      filter - the case-insensitive prefix to match against each column's name.
      Returns:
      one option per matching column, in columns order.
    • fetchDatasources

      public static List<DatasourceRpc.DatasourceMetaInfo> fetchDatasources() throws DatasourceFetchException
      Fetches all datasources currently on the gateway.
      Returns:
      the gateway's datasources.
      Throws:
      DatasourceFetchException - if the fetch fails.
    • fetchTables

      public static List<String> fetchTables(String datasource) throws DatasourceFetchException
      Fetches all tables in datasource.
      Parameters:
      datasource - the name of the datasource to fetch tables from.
      Returns:
      the names of the tables in datasource.
      Throws:
      DatasourceFetchException - if the fetch fails.
    • fetchColumns

      public static List<DatasourceRpc.ColumnMetaInfo> fetchColumns(String datasource, String tableName) throws DatasourceFetchException
      Fetches all columns of tableName in datasource.
      Parameters:
      datasource - the name of the datasource containing the table.
      tableName - the name of the table to fetch columns from.
      Returns:
      the columns of tableName.
      Throws:
      DatasourceFetchException - if the fetch fails.
    • createColumnsForToolCall

      public static String createColumnsForToolCall(List<DatasourceRpc.ColumnMetaInfo> columns, String tableName)
      Turns a list of column metadata into a string representation suitable to return from a tool call
      Parameters:
      columns - a list of column metadata
      tableName - the name of the table
      Returns:
      a string representation of the column suitable for use in a tool call or an error message for no columns reported.