Convert an ingestion spec for SQL-based ingestion

Convert ingestion spec to SQL - 图1info

This page describes SQL-based batch ingestion using the druid-multi-stage-query extension, new in Druid 24.0. Refer to the ingestion methods table to determine which ingestion method is right for you.

If you’re already ingesting data with native batch ingestion, you can use the web console to convert the ingestion spec to a SQL query that the multi-stage query task engine can use to ingest data.

This tutorial demonstrates how to convert the ingestion spec to a query task in the web console.

To convert the ingestion spec to a query task, do the following:

  1. In the Query view of the web console, navigate to the menu bar that includes Run.

  2. Click the ellipsis icon and select Convert ingestion spec to SQL. Convert ingestion spec to SQL

  3. In the Ingestion spec to covert window, insert your ingestion spec. You can use your own spec or the sample ingestion spec provided in the tutorial. The sample spec uses data hosted at https://druid.apache.org/data/wikipedia.json.gz and loads it into a table named wikipedia:

    Show the spec

    1. {
    2. "type": "index_parallel",
    3. "spec": {
    4. "ioConfig": {
    5. "type": "index_parallel",
    6. "inputSource": {
    7. "type": "http",
    8. "uris": [
    9. "https://druid.apache.org/data/wikipedia.json.gz"
    10. ]
    11. },
    12. "inputFormat": {
    13. "type": "json"
    14. }
    15. },
    16. "tuningConfig": {
    17. "type": "index_parallel",
    18. "partitionsSpec": {
    19. "type": "dynamic"
    20. }
    21. },
    22. "dataSchema": {
    23. "dataSource": "wikipedia",
    24. "timestampSpec": {
    25. "column": "timestamp",
    26. "format": "iso"
    27. },
    28. "dimensionsSpec": {
    29. "dimensions": [
    30. "isRobot",
    31. "channel",
    32. "flags",
    33. "isUnpatrolled",
    34. "page",
    35. "diffUrl",
    36. {
    37. "type": "long",
    38. "name": "added"
    39. },
    40. "comment",
    41. {
    42. "type": "long",
    43. "name": "commentLength"
    44. },
    45. "isNew",
    46. "isMinor",
    47. {
    48. "type": "long",
    49. "name": "delta"
    50. },
    51. "isAnonymous",
    52. "user",
    53. {
    54. "type": "long",
    55. "name": "deltaBucket"
    56. },
    57. {
    58. "type": "long",
    59. "name": "deleted"
    60. },
    61. "namespace",
    62. "cityName",
    63. "countryName",
    64. "regionIsoCode",
    65. "metroCode",
    66. "countryIsoCode",
    67. "regionName"
    68. ]
    69. },
    70. "granularitySpec": {
    71. "queryGranularity": "none",
    72. "rollup": false,
    73. "segmentGranularity": "day"
    74. }
    75. }
    76. }
    77. }
  4. Click Submit to submit the spec. The web console uses the JSON-based ingestion spec to generate a SQL query that you can use instead. This is what the query looks like for the sample ingestion spec:

    Show the query

    1. -- This SQL query was auto generated from an ingestion spec
    2. REPLACE INTO wikipedia OVERWRITE ALL
    3. WITH source AS (SELECT * FROM TABLE(
    4. EXTERN(
    5. '{"type":"http","uris":["https://druid.apache.org/data/wikipedia.json.gz"]}',
    6. '{"type":"json"}',
    7. '[{"name":"timestamp","type":"string"},{"name":"isRobot","type":"string"},{"name":"channel","type":"string"},{"name":"flags","type":"string"},{"name":"isUnpatrolled","type":"string"},{"name":"page","type":"string"},{"name":"diffUrl","type":"string"},{"name":"added","type":"long"},{"name":"comment","type":"string"},{"name":"commentLength","type":"long"},{"name":"isNew","type":"string"},{"name":"isMinor","type":"string"},{"name":"delta","type":"long"},{"name":"isAnonymous","type":"string"},{"name":"user","type":"string"},{"name":"deltaBucket","type":"long"},{"name":"deleted","type":"long"},{"name":"namespace","type":"string"},{"name":"cityName","type":"string"},{"name":"countryName","type":"string"},{"name":"regionIsoCode","type":"string"},{"name":"metroCode","type":"string"},{"name":"countryIsoCode","type":"string"},{"name":"regionName","type":"string"}]'
    8. )
    9. ))
    10. SELECT
    11. TIME_PARSE("timestamp") AS __time,
    12. "isRobot",
    13. "channel",
    14. "flags",
    15. "isUnpatrolled",
    16. "page",
    17. "diffUrl",
    18. "added",
    19. "comment",
    20. "commentLength",
    21. "isNew",
    22. "isMinor",
    23. "delta",
    24. "isAnonymous",
    25. "user",
    26. "deltaBucket",
    27. "deleted",
    28. "namespace",
    29. "cityName",
    30. "countryName",
    31. "regionIsoCode",
    32. "metroCode",
    33. "countryIsoCode",
    34. "regionName"
    35. FROM source
    36. PARTITIONED BY DAY
  5. Review the generated SQL query to make sure it matches your requirements and does what you expect.

  6. Click Run to start the ingestion.