Class MongoCatalog

    • Constructor Detail

      • MongoCatalog

        public MongoCatalog()
    • Method Detail

      • initialize

        public void initialize​(java.lang.String name,
                               CaseInsensitiveStringMap options)
        Initializes the MongoCatalog.
        Specified by:
        initialize in interface CatalogPlugin
        Parameters:
        name - the name used to identify and load this catalog
        options - a case-insensitive string map of configuration
      • name

        public java.lang.String name()
        Specified by:
        name in interface CatalogPlugin
        Returns:
        the catalog name
      • listNamespaces

        public java.lang.String[][] listNamespaces()
        List namespaces (databases).
        Specified by:
        listNamespaces in interface SupportsNamespaces
        Returns:
        an array of namespace (database) names
      • listNamespaces

        public java.lang.String[][] listNamespaces​(java.lang.String[] namespace)
                                            throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
        List namespaces (databases).

        As MongoDB only supports top level databases, this will return all databases if the database (namespace array) is empty or any empty array if the database exists.

        Specified by:
        listNamespaces in interface SupportsNamespaces
        Parameters:
        namespace - the optional database array
        Returns:
        an empty array if the database exists
        Throws:
        org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException - If the namespace (database) does not exist
      • loadNamespaceMetadata

        public java.util.Map<java.lang.String,​java.lang.String> loadNamespaceMetadata​(java.lang.String[] namespace)
                                                                                     throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
        Currently only returns an empty map if the namespace (database) exists.
        Specified by:
        loadNamespaceMetadata in interface SupportsNamespaces
        Parameters:
        namespace - (database) a multi-part namespace
        Returns:
        a string map of properties for the given namespace
        Throws:
        org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException - If the namespace (database) does not exist
      • namespaceExists

        public boolean namespaceExists​(java.lang.String[] namespace)
        Test whether a namespace (database) exists.
        Specified by:
        namespaceExists in interface SupportsNamespaces
        Parameters:
        namespace - (database) a multi-part namespace
        Returns:
        true if the namespace (database) exists, false otherwise
      • createNamespace

        public void createNamespace​(java.lang.String[] namespace,
                                    java.util.Map<java.lang.String,​java.lang.String> metadata)
                             throws org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException
        Create a database.

        As databases can be created automatically when creating a collection in MongoDB this method only checks to ensure that the database doesn't already exist.

        Specified by:
        createNamespace in interface SupportsNamespaces
        Parameters:
        namespace - (database) a multi-part namespace
        metadata - a string map of properties for the given namespace
        Throws:
        org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException - If the namespace (database) already exists
        java.lang.UnsupportedOperationException - If create is not a supported operation
      • alterNamespace

        public void alterNamespace​(java.lang.String[] namespace,
                                   NamespaceChange... changes)
        Altering databases is currently not supported, so alterNamespace will always throw an exception.
        Specified by:
        alterNamespace in interface SupportsNamespaces
        Parameters:
        namespace - (database) a multi-part namespace
        changes - a collection of changes to apply to the namespace
        Throws:
        java.lang.UnsupportedOperationException - If namespace (database) properties are not supported
      • dropNamespace

        public boolean dropNamespace​(java.lang.String[] namespace)
        Drop a database.
        Specified by:
        dropNamespace in interface SupportsNamespaces
        Parameters:
        namespace - (database) a multi-part namespace
        Returns:
        true if the namespace (database) was dropped
      • listTables

        public Identifier[] listTables​(java.lang.String[] namespace)
        List the collections in a namespace (database).

        Note: Will only return collections and not views.

        Specified by:
        listTables in interface TableCatalog
        Parameters:
        namespace - (database) a multi-part namespace
        Returns:
        an array of Identifiers for tables (collections)
      • tableExists

        public boolean tableExists​(Identifier identifier)
        Test whether a collection exists.
        Specified by:
        tableExists in interface TableCatalog
        Parameters:
        identifier - a collection identifier
        Returns:
        true if the collection exists, false otherwise
      • loadTable

        public Table loadTable​(Identifier identifier)
                        throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
        Load collection.
        Specified by:
        loadTable in interface TableCatalog
        Parameters:
        identifier - a collection identifier
        Returns:
        the table's metadata
        Throws:
        org.apache.spark.sql.catalyst.analysis.NoSuchTableException - If the collection doesn't exist or is a view
      • createTable

        public Table createTable​(Identifier identifier,
                                 StructType schema,
                                 Transform[] partitions,
                                 java.util.Map<java.lang.String,​java.lang.String> properties)
                          throws org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
        Create a collection.
        Specified by:
        createTable in interface TableCatalog
        Parameters:
        identifier - a collection identifier
        schema - the schema of the new table, as a struct type
        partitions - transforms to use for partitioning data in the table
        properties - a string map of collection properties
        Returns:
        metadata for the new table
        Throws:
        org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException - If a collection or view already exists for the identifier
        java.lang.UnsupportedOperationException - If a requested partition transform is not supported
      • alterTable

        public Table alterTable​(Identifier identifier,
                                TableChange... changes)
                         throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
        Altering collections is currently not supported, so alterTable will always throw an exception.
        Specified by:
        alterTable in interface TableCatalog
        Parameters:
        identifier - a collection identifier
        changes - changes to apply to the table
        Returns:
        will throw an exception as altering collections is not supported.
        Throws:
        org.apache.spark.sql.catalyst.analysis.NoSuchTableException - If the collection doesn't exist or is a view
        java.lang.IllegalArgumentException - If any change is rejected by the implementation.
      • dropTable

        public boolean dropTable​(Identifier identifier)
        Drop a collection.
        Specified by:
        dropTable in interface TableCatalog
        Parameters:
        identifier - a collection identifier
        Returns:
        true if a collection was deleted, false if no collection exists for the identifier
      • renameTable

        public void renameTable​(Identifier oldIdentifier,
                                Identifier newIdentifier)
                         throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException,
                                org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
        Renames a collection.
        Specified by:
        renameTable in interface TableCatalog
        Parameters:
        oldIdentifier - the collection identifier of the existing collection to rename
        newIdentifier - the new collection identifier of the table
        Throws:
        org.apache.spark.sql.catalyst.analysis.NoSuchTableException - If the collection to rename doesn't exist or is a view
        org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException - If the new collection name already exists or is a view