import_export_datasources.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. .. Licensed to the Apache Software Foundation (ASF) under one
  2. or more contributor license agreements. See the NOTICE file
  3. distributed with this work for additional information
  4. regarding copyright ownership. The ASF licenses this file
  5. to you under the Apache License, Version 2.0 (the
  6. "License"); you may not use this file except in compliance
  7. with the License. You may obtain a copy of the License at
  8. .. http://www.apache.org/licenses/LICENSE-2.0
  9. .. Unless required by applicable law or agreed to in writing,
  10. software distributed under the License is distributed on an
  11. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, either express or implied. See the License for the
  13. specific language governing permissions and limitations
  14. under the License.
  15. Importing and Exporting Datasources
  16. ===================================
  17. The superset cli allows you to import and export datasources from and to YAML.
  18. Datasources include both databases and druid clusters. The data is expected to be organized in the following hierarchy: ::
  19. .
  20. ├──databases
  21. | ├──database_1
  22. | | ├──table_1
  23. | | | ├──columns
  24. | | | | ├──column_1
  25. | | | | ├──column_2
  26. | | | | └──... (more columns)
  27. | | | └──metrics
  28. | | | ├──metric_1
  29. | | | ├──metric_2
  30. | | | └──... (more metrics)
  31. | | └── ... (more tables)
  32. | └── ... (more databases)
  33. └──druid_clusters
  34. ├──cluster_1
  35. | ├──datasource_1
  36. | | ├──columns
  37. | | | ├──column_1
  38. | | | ├──column_2
  39. | | | └──... (more columns)
  40. | | └──metrics
  41. | | ├──metric_1
  42. | | ├──metric_2
  43. | | └──... (more metrics)
  44. | └── ... (more datasources)
  45. └── ... (more clusters)
  46. Exporting Datasources to YAML
  47. -----------------------------
  48. You can print your current datasources to stdout by running: ::
  49. superset export_datasources
  50. To save your datasources to a file run: ::
  51. superset export_datasources -f <filename>
  52. By default, default (null) values will be omitted. Use the ``-d`` flag to include them.
  53. If you want back references to be included (e.g. a column to include the table id
  54. it belongs to) use the ``-b`` flag.
  55. Alternatively, you can export datasources using the UI:
  56. 1. Open **Sources** -> **Databases** to export all tables associated to a
  57. single or multiple databases. (**Tables** for one or more tables,
  58. **Druid Clusters** for clusters, **Druid Datasources** for datasources)
  59. #. Select the items you would like to export
  60. #. Click **Actions** -> **Export to YAML**
  61. #. If you want to import an item that you exported through the UI, you
  62. will need to nest it inside its parent element, e.g. a `database`
  63. needs to be nested under `databases` a `table` needs to be
  64. nested inside a `database` element.
  65. Exporting the complete supported YAML schema
  66. --------------------------------------------
  67. In order to obtain an exhaustive list of all fields you can import using the YAML import run: ::
  68. superset export_datasource_schema
  69. Again, you can use the ``-b`` flag to include back references.
  70. Importing Datasources from YAML
  71. -------------------------------
  72. In order to import datasources from a YAML file(s), run: ::
  73. superset import_datasources -p <path or filename>
  74. If you supply a path all files ending with ``*.yaml`` or ``*.yml`` will be parsed.
  75. You can apply additional flags e.g.: ::
  76. superset import_datasources -p <path> -r
  77. Will search the supplied path recursively.
  78. The sync flag ``-s`` takes parameters in order to sync the supplied elements with
  79. your file. Be careful this can delete the contents of your meta database. Example:
  80. superset import_datasources -p <path / filename> -s columns,metrics
  81. This will sync all ``metrics`` and ``columns`` for all datasources found in the
  82. ``<path / filename>`` in the Superset meta database. This means columns and metrics
  83. not specified in YAML will be deleted. If you would add ``tables`` to ``columns,metrics``
  84. those would be synchronised as well.
  85. If you don't supply the sync flag (``-s``) importing will only add and update (override) fields.
  86. E.g. you can add a ``verbose_name`` to the column ``ds`` in the table ``random_time_series`` from the example datasets
  87. by saving the following YAML to file and then running the ``import_datasources`` command. ::
  88. databases:
  89. - database_name: main
  90. tables:
  91. - table_name: random_time_series
  92. columns:
  93. - column_name: ds
  94. verbose_name: datetime