public List getTables()

in seatunnel-datasource/seatunnel-datasource-plugins/datasource-jdbc-postgresql/src/main/java/org/apache/seatunnel/datasource/plugin/postgresql/jdbc/PostgresqlDataSourceChannel.java [58:116]


    public List<String> getTables(
            @NonNull String pluginName,
            Map<String, String> requestParams,
            String database,
            Map<String, String> options) {
        List<String> tableNames = new ArrayList<>();
        StringBuilder queryWhere = new StringBuilder();
        String query =
                "SELECT table_schema, table_name FROM information_schema.tables\n"
                        + "WHERE table_schema NOT IN ('information_schema', 'pg_catalog', 'root', 'pg_toast', 'pg_temp_1', 'pg_toast_temp_1', 'postgres', 'template0', 'template1')\n";
        queryWhere.append(query);
        String filterName = options.get("filterName");
        if (StringUtils.isNotEmpty(filterName)) {
            String[] split = filterName.split("\\.");
            if (split.length == 2) {
                queryWhere
                        .append("AND (table_schema LIKE '")
                        .append(split[0].contains("%") ? split[0] : "%" + split[0] + "%")
                        .append("'")
                        .append(" AND table_name LIKE '")
                        .append(split[1].contains("%") ? split[1] : "%" + split[1] + "%")
                        .append("')");
            } else {
                String filterNameRep =
                        filterName.contains("%") ? filterName : "%" + filterName + "%";
                queryWhere
                        .append(" AND (table_schema LIKE '")
                        .append(filterNameRep)
                        .append("'")
                        .append(" OR table_name LIKE '")
                        .append(filterNameRep)
                        .append("')");
            }
        }
        String size = options.get("size");
        if (StringUtils.isNotEmpty(size)) {
            queryWhere.append(" LIMIT ").append(size);
        }
        log.info(queryWhere.toString());
        requestParams.put(
                PostgresqlOptionRule.URL.key(),
                JdbcUtils.replaceDatabase(
                        requestParams.get(PostgresqlOptionRule.URL.key()), database));
        try (Connection connection = getConnection(requestParams)) {
            try (Statement statement = connection.createStatement();
                    ResultSet resultSet = statement.executeQuery(queryWhere.toString())) {
                while (resultSet.next()) {
                    String schemaName = resultSet.getString("table_schema");
                    String tableName = resultSet.getString("table_name");
                    if (StringUtils.isNotBlank(schemaName)) {
                        tableNames.add(schemaName + "." + tableName);
                    }
                }
            }
            return tableNames;
        } catch (SQLException | ClassNotFoundException e) {
            throw new DataSourcePluginException("get table names failed", e);
        }
    }