|
| 1 | +.. _query-with-sql: |
| 2 | + |
| 3 | +================= |
| 4 | +Querying with SQL |
| 5 | +================= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. include:: /includes/fact-sql-beta-message.rst |
| 10 | + |
| 11 | +{+adl+} supports SQL format queries through the :ref:`JDBC driver |
| 12 | +<jdbc-driver>` for {+adl+} and using the :ref:`adl-sql-stage` |
| 13 | +:ref:`aggregation pipeline <adl-aggregation-pipeline>` stage. To support |
| 14 | +SQL format queries, {+adl+} automatically creates a |json| schema that maps |
| 15 | +to a relational schema of columns, tables, and databases for all new |
| 16 | +collections, except wildcard (``*``) collections, and views in the {+dl+} |
| 17 | +storage configuration. To learn more about the schema, see |
| 18 | +:ref:`sql-schema-format`. |
| 19 | + |
| 20 | +{+dl+} automatically generates a schema for a new non-wildcard collection or |
| 21 | +view in the storage configuration when you: |
| 22 | + |
| 23 | +- :ref:`Create <dl-create-collection-views-cmd>` the collection or view |
| 24 | + in the storage configuration. |
| 25 | + |
| 26 | +- :ref:`Rename <dl-rename-collection-cmd>` a collection or view that does not |
| 27 | + already have a schema. If you rename a collection or view that already has |
| 28 | + a schema, the schema is also renamed. {+dl+} does not generate a new schema |
| 29 | + for a renamed collection or view if it already exists. |
| 30 | + |
| 31 | +- :ref:`Set <datalake-setstorageconfig>` the storage configuration. |
| 32 | + |
| 33 | +.. include:: /includes/fact-schema-for-existing-collections.rst |
| 34 | + |
| 35 | +By default, {+dl+} samples data from only one randomly selected document in |
| 36 | +your non-wildcard collection or view to generate a |json| schema. If your |
| 37 | +collection or view contains polymorphic data, you can provide a larger |
| 38 | +sampling size to {+dl+} to generate a new schema or you can manually |
| 39 | +construct and set the schema. |
| 40 | + |
| 41 | +You can manually generate schemas for all collections and views using the |
| 42 | +:ref:`sqlgenerateschema-cmd` command, set or update the schema for your |
| 43 | +collections or views using the :ref:`sqlsetschema-cmd` command, and view |
| 44 | +the stored schema using the :ref:`sqlgetschema-cmd` command. |
| 45 | + |
| 46 | +Once the SQL schema is set up, you can query your {+adl+} collections or views |
| 47 | +through the :ref:`JDBC driver <jdbc-driver>` for {+adl+} and using the |
| 48 | +:ref:`adl-sql-stage` :ref:`aggregation pipeline <adl-aggregation-pipeline>` |
| 49 | +stage. |
| 50 | + |
| 51 | +You can manually delete a schema for a collection or view by running the |
| 52 | +:ref:`sqlsetschema-cmd` command with an empty schema document. {+dl+} |
| 53 | +automatically removes the schema for a collection or view when you: |
| 54 | + |
| 55 | +- :ref:`Drop the collection or view <dl-drop-collection-views-cmd>` from the |
| 56 | + storage configuration. |
| 57 | +- :ref:`Modify the storage configuration <datalake-setstorageconfig>` to |
| 58 | + remove the collection or view from the storage configuration. |
| 59 | +- :ref:`Drop the database <dl-drop-database-cmd>` that contains the collection |
| 60 | + or view from the storage configuration. |
| 61 | + |
| 62 | +.. class:: hidden |
| 63 | + |
| 64 | + .. toctree:: |
| 65 | + :titlesonly: |
| 66 | + |
| 67 | + SQL Schema Format </reference/config-files/sql-schema-format> |
| 68 | + Generate SQL Schema </reference/cli/sql/sqlgenerateschema> |
| 69 | + Set SQL Schema </reference/cli/sql/sqlsetschema> |
| 70 | + Retrieve SQL Schema </reference/cli/sql/sqlgetschema> |
| 71 | + Connect Using JDBC Driver </tutorial/jdbc-driver> |
0 commit comments