You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/11/16 20:14:25 UTC

[GitHub] [druid] gianm opened a new issue #11929: Batch ingestion using SQL INSERT

gianm opened a new issue #11929:
URL: https://github.com/apache/druid/issues/11929


   Everyone likes doing things with SQL, so let's make it so people can do batch ingestion using SQL INSERT! I'd like to make it possible to write an [INSERT INTO .... SELECT](https://support.microsoft.com/en-us/office/insert-into-statement-e12fd58b-33b1-479c-8221-e9f245ab8d24) query like this:
   
   ```sql
   INSERT INTO tbl
   SELECT
     TIME_PARSE("timestamp") AS __time,
     channel,
     cityName,
     countryName
   FROM TABLE(
       EXTERN(
         '{"type": "s3", "uris": ["s3://bucket/file"]}',
         '{"type": "json"}',
         '[{"name": "channel", "type": "string"}, {"name": "cityName", "type": "string"}, {"name": "countryName", "type": "string"}, {"name": "timestamp", "type": "string"}]'
       )
     )
   BUCKET BY FLOOR(__time TO DAY)
   ORDER BY channel
   ```
   
   Since this work may take some time to execute, there will need to be some sort of asynchronous results API. I'm thinking a good choice would be to return an ingestion task ID immediately, so the standard Druid task APIs can be used to check its status. So the response would look like this (with object result format):
   
   ```json
   [{"taskId": "xyzzy"}]
   ```
   
   Some thoughts about pieces of that query.
   
   ```
   INSERT INTO tbl
   ```
   
   In Druid there is not really a "create datasource" concept, or a datasource-wide schema. Datasources exist when they have data, and their schema is whatever data happened to get loaded. Creating a new datasource and loading more data into an existing one are the same API. So I suggest we carry those semantics over to SQL, and do ingestions (both new-table and existing-table) with the "INSERT" command.
   
   It's possible that at some point we'll want to introduce a datasource-wide schema (or partial schema), or add the ability to create empty datasources. At that point it would make sense to also add a "CREATE TABLE" command to SQL. But I suggest we start with a versatile "INSERT".
   
   ---
   
   ```
   SELECT
     TIME_PARSE("timestamp") AS __time,
     channel,
     cityName,
     countryName
   ```
   
   The SELECT column list would become the columns that get ingested.
   
   ---
   
   ```
   FROM TABLE(
       EXTERN(
         '{"type": "s3", "uris": ["s3://bucket/file"]}',
         '{"type": "json"}',
         '[{"name": "channel", "type": "string"}, {"name": "cityName", "type": "string"}, {"name": "countryName", "type": "string"}, {"name": "timestamp", "type": "string"}]'
       )
     )
   ```
   
   We need some way to reference external data. I suggest we start with a table function that accepts an [input source](https://druid.apache.org/docs/latest/ingestion/native-batch.html#input-sources) and [input format](https://druid.apache.org/docs/latest/ingestion/data-formats.html#input-format). This example uses an S3 input source and JSON input format.
   
   The "EXTERN" function in this example also accepts a row signature. That's because the SQL planner will need column name and type information in order to validate and plan a query. I think this is OK at first, but at some point I'd like to make it possible to discover this stuff at runtime.
   
   At some point it'd be nice to have the syntax here be more SQL-y (instead of having this embedded JSON). I think it'd be possible to do that by adding a bunch of new table functions alongside the existing input sources and formats. But I thought it'd be good to start with this generic one.
   
   ---
   
   ```
   BUCKET BY FLOOR(__time TO DAY)
   ```
   
   We need some way to specify segment granularity. Adding a "BUCKET BY" keyword seems like a natural way to do this.
   
   ---
   
   ```
   ORDER BY channel
   ```
   
   We need some way to specify how segments are partitioned, and how rows are ordered within segments. Using "ORDER BY" seems like a natural way to do this, especially for range-based partitioning. (For hash, I'm imagining something like `ORDER BY HASH(foo, bar)`.)
   
   In my experience, it's a good idea to partition and order-within-partitions using the same key, so I think it's OK to have both controlled by "ORDER BY". But if we needed to support them using different keys, I could imagine introducing a "PARTITION BY" in addition to "ORDER BY".
   
   ---
   
   ### Proposed changes
   
   Specific proposed changes:
   
   1) Add parser and validator support for INSERT, including ability to authorize using WRITE DATASOURCE permissions.
   
   2) Add an EXTERN table function and an "external" DataSource type that represents external data. The "external" DataSource would be used by the SQL layer to represent ingestion sources, and would be used to help generate ingestion tasks, but it would not understood by the native query execution system.
   
   3) Structure planning such that only Scan and GroupBy are used as the native query types for INSERT. (Scan represents ingestion without rollup, GroupBy represents ingestion with rollup.)
   
   4) Add an "orderBy" parameter to the Scan query to encapsulate the "ORDER BY" SQL clause. (This doesn't need to be executable in the native query system at first, but it'd be great to make that possible too at some point.)
   
   5) Split QueryMaker into an interface so there can be one implementation that executes SELECT queries and one implementation that executes INSERT queries.
   
   6) Add an INSERT-oriented QueryMaker that runs Scan and GroupBy queries as batch ingestion tasks. Virtual columns are like [transformSpec](https://druid.apache.org/docs/latest/ingestion/ingestion-spec.html#transformspec), aggregation functions are like [metricsSpec](https://druid.apache.org/docs/latest/ingestion/ingestion-spec.html#metricsspec), GROUP BY is like [dimensionsSpec](https://druid.apache.org/docs/latest/ingestion/ingestion-spec.html#dimensionsspec) with rollup, BUCKET BY is like [segmentGranularity](https://druid.apache.org/docs/latest/ingestion/ingestion-spec.html#granularityspec), etc.
   
   ### Whatabouts
   
   *What about UPDATE, DELETE, and ALTER TABLE?*
   
   Those would be cool too. I think they would be great as future work. UPDATE would be a good way to trigger reindexing jobs that modify actual row values, and ALTER TABLE would be a good way to trigger reindexing jobs that modify partitioning or column types. DELETE, if we're clever, could either trigger reindexing jobs or do some metadata-only thing depending on the parameters of the DELETE.
   
   *What about streaming?*
   
   Calcite (our SQL parser and planning engine) has a bunch of extensions that support streaming SQL: https://calcite.apache.org/docs/stream.html. I haven't studied these yet, but we may be able to use this to extend SQL to support manipulation of streaming supervisors.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] paul-rogers commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
paul-rogers commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026436568


   Couple of thoughts on syntax. In Druid, there appears to be only one "partition" column and that must be some valid unit of time. The other "cluster" columns are like secondary partitions. So, without ambiguity, we could consider: `PARTITION BY DAY, b, c`. In this case, `DAY` is an implicit alias for the corresponding `TIME_FLOOR` expression.
   
   If the time dimension is omitted, then it would be `PARTITION BY ALL, b, c`.  while `ALL` is an alias for a time slice of (near) infinite size. If the `PARTITION ` statement is omitted, then it means one big partition over all time with all values. Fine for a test table, maybe not so good for a table at scale.
   
   Then, since we would not need the `CLUSTER` keyword, and since `PARTITION` is already reserved, the expression can go back to the original proposed `PARTITION BY` to be consistent with other uses of `PARTITION`.
   
   The user can also control sort order within a partition. For that, `ORDER BY` is the most logical choice. Implicitly, the partition columns go before the `ORDER BY` columns.
   
   Thus:
   
   ```sql
   INSERT INTO table
   SELECT ...
   PARTITION BY DAY, client, region ORDER BY order_id, line_item
   ```
   
   In the above, the total sort order is `(__time, client, region, order_id, line_item)`.
   
   The first key could also be a valid expression of `__time` which, at present, is only `TIME_FLOOR`. This allows special-case partitions such as 2 days or 8 hours without needing keywords for each of these cases. (The analyzer can reject any unit which Druid might not support.)
   
   For the replace, we might want to handle the general case, which is an `UPDATE` or `DELETE` statement. To reflect a company name change:
   
   ```sql
   UPDATE table
   SET company = 'XYZ Corp.'
   WHERE company = 'ABC LLC'
   ```
   
   To remove all of Bob's data due to a GPDR request:
   
   ```sql
   DELETE FROM table
   WHERE userId = 'bob'
   ```
   
   Druid might not support these yet, but they seem reasonable (if expensive) operations. Given that, we might observe that the standard form of SQL is verb + details. So, for the replace partition, maybe go with the Spark syntax:
   
   ```sql
   INSERT OVERWRITE table
   PARTITION _time = <time const>
   SELECT ...
   PARTITION BY ...
   ```
   
   The parser should handle the dual use of `PARTITION` because one is always followed by `BY` the other never is. 
   
   Or, to be more general:
   
   ```sql
   INSERT OVERWRITE table
   WHERE _time = <time const>
   SELECT ...
   PARTITION BY ...
   ```
   
   The above is logically equivalent to a `DELETE` statement followed by an `INSERT`. Since Druid does not support compound statements, we glom both operations together.
   
   The above allows replacing any set of keys, with the time partition as a special case. If the present version only supports replacing a time partition, we simply require that the `WHERE` class have exactly one equality condition on only the `__time` clause. That is, we design the syntax for the general case, but use semantic analysis to restrict usage to the one case supported today.
   
   Or, if we really want to call out that we can only replace the "primary" date partition, and none of the other keys:
   
   ```sql
   INSERT OVERWRITE table
   WHERE PARTITION = <time const>
   SELECT ...
   PARTITION BY ...
   ```
   
   But, the above seems overkill.
   
   If we want a new verb, replace `INSERT OVERWRITE` with `REPLACE WITHIN` (`REPLACE ` is a MySQL reserved word while `WITHIN` is a [SQL-2016 reserved word](https://en.wikipedia.org/wiki/SQL_reserved_words)):
   
   ```sql
   REPLACE WITHIN table
   WHERE _time = <time const>
   SELECT ...
   PARTITION BY ...
   ```
   
   One final issue is that we have the user specify the partition in every statement. In most cases, there is only one correct value: that used yesterday, and the day before and... Today we have to repeat ourselves because there is no other source of information. Suppose we stored the partitioning as part of the schema, as in Hive. Then we get:
   
   ```sql
   INSERT INTO table
   SELECT ...
   ```
   
   With partitioning and sorting being that defined in the schema. The above is just plain SQL, of the kind that any tool can produce, which is a nice win.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] abhishekagarwal87 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-971221724


   Thanks, @gianm. This is a really neat way of doing batch ingestion. In this new way of doing batch ingestion, how would we specify tuningConfig e.g.max rows in memory, max bytes in memory, number of segments to merge, etc?  It seems intuitive to have a QueryContext for INSERT queries similar to SELECT and such tuning configurations can go there. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-971336455


   As for the partition, I think an independent `PARTITION BY` is more flexible. ClickHouse also provides optional `PARTITION BY` keyword. If it's not specified, data would be partitioned. 
   
   https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree/
   > PARTITION BY — The partitioning key. Optional. In most cases you don't need partition key, and in most other cases you don't need partition key more granular than by months. Partitioning does not speed up queries (in contrast to the ORDER BY expression). You should never use too granular partitioning. Don't partition your data by client identifiers or names (instead make client identifier or name the first column in the ORDER BY expression).
   
   > For partitioning by month, use the toYYYYMM(date_column) expression, where date_column is a column with a date of the type Date. The partition names here have the "YYYYMM" format.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026515751


   This part:
   
   > Thus:
   > 
   > ```
   > INSERT INTO table
   > SELECT ...
   > PARTITION BY DAY, client, region ORDER BY order_id, line_item
   > ```
   > 
   > In the above, the total sort order is (__time, client, region, order_id, line_item).
   
   Makes me a little nervous because it suggests that the "PARTITION BY" will give you a total sorting for the table. But it might not, if the data is inserted in a sequence of INSERT calls. Each one will individually be sorted but there won't be a global sort until a compaction runs.
   
   However, there _will_ still be a global time-partition-key-sort (a.k.a. segment-granular sort), because we _strictly_ partition segments by the time partition key. There is exactly one time partition key (segment-granular timestamp) per segment, so we can always get a total ordering there. Not so for the secondary partitioning: because we have a variety of key values per segment, appending more segments can result in a non-totally-ordered situation. So that's another big difference between the time partitioning and the secondary partitioning.
   
   The mixing of keywords and expressions is also a little weird…
   
   This reflection is making me think that time partitioning is truly and overwhelmingly special, and so it really is a good idea to have the keywords be different. Which takes us back to CLUSTER BY (or CLUSTERED BY) being separate.
   
   Personally, after this reflection I'm a fan of:
   
   - PARTITIONED BY is _required_ and can either be a time floor function like `PARTITION BY FLOOR(__time TO DAY)` or `PARTITION BY TIME_FLOOR(__time, 'PT1H')`, a time unit like `PARTITION BY HOUR`, `PARTITION BY DAY`, `PARTITION BY MONTH`, or `PARTITION BY YEAR`; or the special phrase `PARTITION BY ALL TIME`. If you use the expression form, and provide an expression that is not a recognizable time floor expression, it's an error.
   - CLUSTERED BY is an _optional_ list of normal SQL expressions, and whatever you provide there, we'll use for secondary partitioning. If you provide nothing, we'll still do some kind of secondary partitioning, but it's up to us how we're going to do it.
   
   If there's a hypothetical future world where time partitioning isn't as special as it is today, we could loosen some of this stuff up, and perhaps move towards only using one clause. But we don't have plans right now to loosen this up, so I think it makes sense for the syntax to reflect the specialness of time.
   
   ----
   
   As to how to replace time chunks, I kind of like using the verb REPLACE instead of INSERT. It makes sense to me to have append and overwrite both be top-level verbs. The way they work is very different, so the high-level distinction is good. There's also precedent in MySQL: https://dev.mysql.com/doc/refman/5.7/en/replace.html
   
   This version appeals to me, which is similar to MySQL's version:
   
   ```
   REPLACE
   [INTO] table
   FOR <partitionSpec | (partitionSpec, partitionSpec, ...)>
   [insert-style column list]
   SELECT ...
   PARTITION BY ...
   ```
   
   Where partitionSpec is one of:
   
   - PARTITION followed by SQL literal timestamp, like `PARTITION TIMESTAMP '2000-01-01 00:00:00'`: refers to the partition that starts with this timestamp. Must be aligned to the query's PARTITION BY.
   - PARTITION followed by literal string, like `PARTITION '2000-01-01/P1M'`: interpreted as an ISO8601 interval. Must be aligned to the query's PARTITION BY.
   - Keyword `ALL TIME`. Causes the whole table to be replaced.
   
   And the "FOR clause" is required. (I'm worried that making it optional will encourage accidental whole-table-replacement.)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1023654380


   PR #12163 is adding the PARTITON BY / CLUSTER BY syntax. That's great. I'd like to propose some additional syntax for controlling replace vs append, like what we do with `intervals` and `appendToExisting` in ingestion specs today.
   
   The idea is based on Spark's `INSERT OVERWRITE`, which is a similar concept: https://spark.apache.org/docs/latest/sql-ref-syntax-dml-insert-overwrite-table.html. However, I suggest a few changes for our situation:
   
   1) REPLACE is already a keyword in our dialect, so use that instead of OVERWRITE to avoid adding a new keyword.
   2) We only support time partitioning, so include some nice nods to that in the syntax.
   3) We don't have "partition by" metadata on the table, so it'd have to be provided in the query.
   
   For example, this query would overwrite the entire datasource `tbl`:
   
   ```
   INSERT INTO tbl
   REPLACE ALL
     SELECT …
     PARTITION BY DAY
   ```
   
   This query would overwrite the day 2020-01-01:
   
   ```
   INSERT INTO tbl
   REPLACE PARTITION TIMESTAMP '2020-01-01 00:00:00' -- SQL literal timestamp
     SELECT …
     PARTITION BY DAY
   ```
   
   This query would overwrite the month 2020-01. Note that in this example, the partition interval spans multiple partitions. I think this is OK and will be useful for jobs that want to replace a bunch of time chunks all at once. I wish it would say PARTITIONS instead of PARTITION, but PARTITIONS isn't a keyword currently and I'd like to avoid adding a new one.
   
   ```
   INSERT INTO tbl
   REPLACE PARTITION '2020-01/P1M' -- ISO8601 interval
     SELECT …
     PARTITION BY DAY
   ```
   
   Validation conditions:
   
   1. With `REPLACE PARTITION TIMESTAMP '<sql timestamp>'`, the timestamp must be aligned to the provided `PARTITION BY` (it must be the starting timestamp of a time chunk).
   2. With `REPLACE PARTITION '<iso8601 interval>'`, the interval must be aligned to the provided `PARTITION BY`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-973816864


   > I think this would be pretty straight-forward to do, so I think it makes sense to add a few of these common ones before we ship the feature. (In addition to "fall-back" EXTERN.)
   > 
   > Btw, I feel it's kind of annoying to have the type signature there, but the reason it's there is that the planner needs to know the signature of the data that is being selected, before the data is actually inspected. At some point I'd like to explore ways we can get rid of the type signature in some cases or even all cases. But I had it there for now, because it fits into the existing planner better.
   > 
   > Anyway, what do you think?
   
   @gianm I think it's OK for us to start with a JSON formatted parameter. As for the type signature, I want to know do we have plan to support DDL such as CREATE TABLE? If DDL is supported, we can split the type signatures into a CREATE TABLE statement which would be more convenient for users to get started with Druid.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm edited a comment on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm edited a comment on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-973174010


   > As for the partition, I think an independent PARTITION BY is more flexible. ClickHouse also provides optional PARTITION BY keyword. If it's not specified, data would not be partitioned.
   
   @FrankChen021 It sounds like that PARTITION BY is similar to Druid "segment granularity". I was suggesting we call that "BUCKET BY" but "PARTITION BY" does seem to be more common. To try to figure out what we should do, I did some research into how these things are usually called.
   
   One concept is "splitting the dataset into subsets, where each subset has a _single value_ of a key". This is often used to simplify data management, because it enables rewriting that one partition without touching anything else. It's common for the key to be some time function like hour, day, or month. This is supported by a variety of dbs, although not all of them. It seems like "PARTITION BY" or "PARTITIONED BY" is the most common term:
   
   - Druid: segmentGranularity
   - BigQuery: [PARTITION BY](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression)
   - Snowflake: does not appear to offer this
   - Redshift: does not appear to offer this
   - Hive: [PARTITIONED BY](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable)
   - Spark SQL: [PARTITIONED BY](https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.html)
   
   Another concept is "colocating data with same or similar values of a key". This is used to improve compression and query performance. It's supported by every db I checked.
   
   - Druid: partitionsSpec
   - BigQuery: [CLUSTER BY](https://cloud.google.com/bigquery/docs/creating-clustered-tables)
   - Snowflake: [CLUSTER BY](https://docs.snowflake.com/en/sql-reference/sql/create-table.html)
   - Redshift: [SORTKEY](https://docs.aws.amazon.com/redshift/latest/dg/t_Sorting_data.html)
   - Hive: [CLUSTERED BY](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable)
   - Spark SQL: [CLUSTERED BY](https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.html)
   
   With all this in mind it seems like the most conventional language would be PARTITION BY for segment granularity and CLUSTER BY for secondary partitioning. Meaning the query would look like:
   
   ```sql
   INSERT INTO tbl
   SELECT ...
   FROM ...
   PARTITION BY FLOOR(__time TO DAY)
   CLUSTER BY channel
   ```
   
   I think there is some risk here of confusion with "PARTITION BY" vs. Druid's "partitionsSpec" ingestion config, which also uses the word "partition" but refers more to the "clustering" concept. But I could believe this is fine for the sake of having the SQL language be more aligned with other DBs.
   
   I'm ok with going with this language. What do people think?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-973813297


   > With all this in mind it seems like the most conventional language would be PARTITION BY for segment granularity and CLUSTER BY for secondary partitioning. Meaning the query would look like:
   > 
   > ```sql
   > INSERT INTO tbl
   > SELECT ...
   > FROM ...
   > PARTITION BY FLOOR(__time TO DAY)
   > CLUSTER BY channel
   > ```
   > 
   > I think there is some risk here of confusion with "PARTITION BY" vs. Druid's "partitionsSpec" ingestion config, which also uses the word "partition" but refers more to the "clustering" concept. But I could believe this is fine for the sake of having the SQL language be more aligned with other DBs.
   > 
   > I'm ok with going with this language. What do people think?
   
   I think these two key words have very clear semantics here. It's pretty much intuitive for users to understand their meanings.
   And they naturally reflect Druid's segment granularity and partitionSpec concept.
   
   ClickHouse's PARTITION BY supports both of these two semantics (as below), but in most user cases that I know, users prefer to partition data by date which is similar to Druid's segment granularity. 
   
   ```sql
   CREATE TABLE table_with_where
   (
       d DateTime,
       a Int
   )
   ENGINE = MergeTree
   PARTITION BY toYYYYMM(d)
   
   
   CREATE TABLE table_for_recompression
   (
       d DateTime,
       key UInt64,
       value String
   ) ENGINE MergeTree()
   PARTITION BY key
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] abhishekagarwal87 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026552672


   I prefer separate clauses for time partitioning and secondary partitioning. It would have been fine if the distinction between primary and secondary partitioning was only an internal detail. But it is not and requires users to pass the input/argument dimension in a very different way depending on what kind of partitioning the input is for. 
   
   For example for the primary partitioning, we accept special keywords like ALL (or None) but not for the secondary partitioning.  Similarly for secondary partitioning, we support multiple schemes such as range, hash, etc. Specifying these additional properties that go beyond column names/expressions makes syntax unwieldy if both cluster-by and partition-by are under one clause. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm edited a comment on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm edited a comment on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-974315460


   It sounds like PARTITION BY and CLUSTER BY are the winners! Works for me.
   
   I'm planning to put up a patch soon with the initial work to support planning INSERT (parts 1–3 and 5 from the "Proposed changes" list in the original proposal). I probably won't do any special parser stuff in that patch, since I think it'll get too complicated to try to do it all at once. So it will probably need to be a sequence of a few patches to get everything in place.
   
   > As for the type signature, I want to know do we have plan to support DDL such as CREATE TABLE? If DDL is supported, we can split the type signatures into a CREATE TABLE statement which would be more convenient for users to get started with Druid.
   
   @FrankChen021 I don't have a solid plan but I would like to support CREATE TABLE at some point. I imagine it would involve having a place to put datasource-level metadata like preferred partitioning, preferred schema, etc. I think it is a strength of Druid that datasources don't _have to_ have a strict schema, so I wouldn't want to enforce that, but I think it'd be good to let people create some schema if they want to.
   
   I also imagine that if you _did_ have a schema defined at the table level, then the INSERT command wouldn't necessarily have to always have a type signature, because in many cases it could be inferred from the table schema. So I think at that point we would want to make it optional.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 edited a comment on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 edited a comment on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026969535


   > PARTITIONED BY is required and can either be a time floor function like PARTITION BY FLOOR(__time TO DAY) or PARTITION BY TIME_FLOOR(__time, 'PT1H'), a time unit like PARTITION BY HOUR, PARTITION BY DAY, PARTITION BY MONTH, or PARTITION BY YEAR; or the special phrase PARTITION BY ALL TIME. If you use the expression form, and provide an expression that is not a recognizable time floor expression, it's an error.
   
   I like the time unit expression: PARTITION BY HOUR, PARTITION BY DAY, PARTITION BY MONTH, or PARTITION BY YEAR. Of course, this does not mean that we should only support this way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026964274


   > INSERT INTO table
   SELECT ...
   PARTITION BY DAY, client, region ORDER BY order_id, line_item
   
   IMO, this confuses users. The biggest question is why not put the `order_id` and `line_item` in the `PARTITION BY` clause? or why not put the `client` and `region` in `ORDER BY` clause?
   
   So, separation of partitioning and secondary partitioning is semantically clear. Some other DBMS like ClickHouse also prefer the separated way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 edited a comment on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 edited a comment on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-971336455


   As for the partition, I think an independent `PARTITION BY` is more flexible. ClickHouse also provides optional `PARTITION BY` keyword. If it's not specified, data would not be partitioned. 
   
   https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree/
   > PARTITION BY — The partitioning key. Optional. In most cases you don't need partition key, and in most other cases you don't need partition key more granular than by months. Partitioning does not speed up queries (in contrast to the ORDER BY expression). You should never use too granular partitioning. Don't partition your data by client identifiers or names (instead make client identifier or name the first column in the ORDER BY expression).
   
   > For partitioning by month, use the toYYYYMM(date_column) expression, where date_column is a column with a date of the type Date. The partition names here have the "YYYYMM" format.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm edited a comment on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm edited a comment on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-972938260


   > Thanks, @gianm. This is a really neat way of doing batch ingestion. In this new way of doing batch ingestion, how would we specify tuningConfig e.g.max rows in memory, max bytes in memory, number of segments to merge, etc? It seems intuitive to have a QueryContext for INSERT queries similar to SELECT and such tuning configurations can go there.
   
   @abhishekagarwal87 About this, I was thinking we would use the existing SQL query context: https://druid.apache.org/docs/latest/querying/sql.html#connection-context. The context isn't part of the SQL grammar, but gets submitted alongside the query. At some point we may also want to add a way to put context parameters in the actual SQL grammar itself but I don't think we need to start there.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1023891931


   > PR #12163 is adding the PARTITON BY / CLUSTER BY syntax. That's great. I'd like to propose some additional syntax for controlling replace vs append, like what we do with `intervals` and `appendToExisting` in ingestion specs today.
   > 
   This is a great proposal. It would be very convenient for people to manage data sources and specific partitions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-972958301


   >  We do have protections against SQL-injection-like malicious requests, but with the existing SQL capabilities, we knew that even if we missed something in our protections, the worst that could happen would be read-only operations, possibly from other tenants tables. If this would happen it would be very severe, but less severe than being able to modify the state of druid.
   
   @dbardbar I think there probably will end up being a flag to disable the feature (we usually add these for new features), but in your situation I'd also recommend using Druid's authorization features. You can make sure that when your app sends a user query to Druid, it does that with an account that only has read-only access to certain tables. If the user doesn't have write access then an INSERT would be rejected. Even SELECT queries to other tables will be rejected.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] paul-rogers commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
paul-rogers commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1083548580


   Druid does time-range based replacement. [MySQL does row-based replacement](https://dev.mysql.com/doc/refman/8.0/en/replace.html). So, the Druid syntax has to specify the time range to be replaced:
   
   ```sql
   REPLACE
   [INTO] table
   WHERE __time IN (<start>, <end>)          -- Added
   -- FOR <partitionSpec | (partitionSpec, partitionSpec, ...)> -- Removed
   [insert-style column list]
   SELECT ...
   PARTITION BY ...
   ```
   
   SQL says *what* is to be done, not *how* to do it. That the time range corresponds to a partition is an implementation detail for us to sort out. The SQL planner can analyze the `WHERE` clause to ensure it contains only `__time` and that the start, end are valid. Who knows, maybe we will support some other kind of replacement at some point: let's not encode the rules in the syntax.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026411798


   FYI there are two threads over at #12163 that are discussing alternative syntaxes:
   
   - https://github.com/apache/druid/pull/12163#discussion_r793184301 with some discussion about whether PARTITION BY should accept time units or expressions.
   - https://github.com/apache/druid/pull/12163#discussion_r791569658 with some discussion about whether we should go with PARTITIONED and CLUSTERED instead of PARTITION and CLUSTER.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-971324041


   @gianm This is a great improvement in Druid. I think the `EXTERN` is not intuitive for users. It still has the smell of old JSON supervisor/task spec. I think the way ClickHouse uses is more user friendly. It uses ENGINE or SETTINGS sub-clause to specify the parameters. Below are examples taken from ClickHouse user doc. I think this also answers @abhishekagarwal87 question.
   
   ```
   CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
   (
       name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1],
       name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2],
       ...
   ) ENGINE = Kafka()
   SETTINGS
       kafka_broker_list = 'host:port',
       kafka_topic_list = 'topic1,topic2,...',
       kafka_group_name = 'group_name',
       kafka_format = 'data_format'[,]
       [kafka_row_delimiter = 'delimiter_symbol',]
       [kafka_schema = '',]
       [kafka_num_consumers = N,]
       [kafka_max_block_size = 0,]
       [kafka_skip_broken_messages = N,]
       [kafka_commit_every_batch = 0,]
       [kafka_thread_per_consumer = 0]
   ```
   
   ```
   CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
   (
       name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
       name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
       ...
   ) ENGINE = MySQL('host:port', 'database', 'table', 'user', 'password'[, replace_query, 'on_duplicate_clause'])
   SETTINGS
       [connection_pool_size=16, ]
       [connection_max_tries=3, ]
       [connection_wait_timeout=5, ] /* 0 -- do not wait */
       [connection_auto_close=true ]
   ;
   ```
   
   ```
   CREATE TABLE s3_engine_table (name String, value UInt32)
       ENGINE = S3(path, [aws_access_key_id, aws_secret_access_key,] format, [compression])
       [SETTINGS ...]
   ```
   
   more info can be found here: https://clickhouse.com/docs/en/engines/table-engines/integrations/


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] vogievetsky commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
vogievetsky commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-973413131


   I think it is fine if as part of the SQL API we redefine some words to be more closely aligned to SQL standards (like we do for types). I think the chief benefit of a SQL based API is that it draws on concepts already familiar to people from other systems. I would +1 `PARTITION BY FLOOR(__time TO DAY) CLUSTER BY channel`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-974315460


   It sounds like PARTITION BY and CLUSTER BY are the winners! Works for me.
   
   I'm planning to put up a patch soon with the initial work to support planning INSERT (parts 1–3 and 5 from the "Proposed changes" list in the original proposal). I probably won't do any special parser stuff in that patch, since I think it'll get too complicated to try to do it all at once. So it will probably need to be a sequence of a few patches to get everything in place.
   
   > As for the type signature, I want to know do we have plan to support DDL such as CREATE TABLE? If DDL is supported, we can split the type signatures into a CREATE TABLE statement which would be more convenient for users to get started with Druid.
   
   I don't have a solid plan but I would like to support CREATE TABLE at some point. I imagine it would involve having a place to put datasource-level metadata like preferred partitioning, preferred schema, etc. I think it is a strength of Druid that datasources don't _have to_ have a strict schema, so I wouldn't want to enforce that, but I think it'd be good to let people create some schema if they want to.
   
   I also imagine that if you _did_ have a schema defined at the table level, then the INSERT command wouldn't necessarily have to always have a type signature, because in many cases it could be inferred from the table schema. So I think at that point we would want to make it optional.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] dbardbar commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
dbardbar commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-972580953


   @gianm - I understand the need, and it does seem great. However, I'm a bit worried about security. 
   We have code that handles abstract requests from the user, translates them to SQL, and passes the SQL to Druid. The user has extensive ways to influence the query (filtered fields, etc.) indirectly.
   We do have protections against SQL-injection-like malicious requests, but with the existing SQL capabilities, we knew that even if we missed something in our protections, the worst that could happen would be read-only operations, possibly from other tenants tables. If this would happen it would be very severe, but less severe than being able to modify the state of druid.
   
   In short - would this feature be protected under some user permission, or some global flag?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-972953837


   > I think the EXTERN is not intuitive for users. It still has the smell of old JSON supervisor/task spec. I think the way ClickHouse uses is more user friendly. It uses ENGINE or SETTINGS sub-clause to specify the parameters. Below are examples taken from ClickHouse user doc. I think this also answers @abhishekagarwal87 question.
   
   @FrankChen021 I agree that it would be better to have a way to do this that doesn't involve using the existing JSON objects. However there are two reasons I wanted to start with the JSON-based one, and add friendlier ones later on:
   
   1) It enables us to support all existing sources / formats without needing to make a bunch of new SQL wrappers immediately.
   
   2) It enables existing apps that already know how to generate the JSON objects to switch to SQL more easily. For example it would enable Druid's builtin web console to write an EXTERN function using some of the same models it already has for handling inputsources and inputformats.
   
   However I definitely agree that adding friendlier versions would be good, and new users would probably prefer the friendlier versions. Maybe for the example I had in the original comment, a friendly version would look like:
   
   ```
   FROM S3('s3://bucket/file', JSON(), 'channel:string,cityName:string,countryName:string,timestamp:string')
   ```
   
   I think this would be pretty straight-forward to do, so I think it makes sense to add a few of these common ones before we ship the feature. (In addition to "fall-back" EXTERN.)
   
   Btw, I feel it's kind of annoying to have the type signature there, but the reason it's there is that the planner needs to know the signature of the data that is being selected, before the data is actually inspected. At some point I'd like to explore ways we can get rid of the type signature in some cases or even all cases. But I had it there for now, because it fits into the existing planner better.
   
   Anyway, what do you think?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] FrankChen021 commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
FrankChen021 commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-1026969535


   > PARTITIONED BY is required and can either be a time floor function like PARTITION BY FLOOR(__time TO DAY) or PARTITION BY TIME_FLOOR(__time, 'PT1H'), a time unit like PARTITION BY HOUR, PARTITION BY DAY, PARTITION BY MONTH, or PARTITION BY YEAR; or the special phrase PARTITION BY ALL TIME. If you use the expression form, and provide an expression that is not a recognizable time floor expression, it's an error.
   
   I like the time unit expression: PARTITION BY HOUR, PARTITION BY DAY, PARTITION BY MONTH, or PARTITION BY YEAR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-972938260


   > Thanks, @gianm. This is a really neat way of doing batch ingestion. In this new way of doing batch ingestion, how would we specify tuningConfig e.g.max rows in memory, max bytes in memory, number of segments to merge, etc? It seems intuitive to have a QueryContext for INSERT queries similar to SELECT and such tuning configurations can go there.
   
   @abhishekagarwal87 About this, I was thinking we would use the existing SQL query context: https://druid.apache.org/docs/latest/querying/sql.html#connection-context. The context isn't part of the SQL grammar, but gets submitted alongside the query. At some point we may also want to add a way to put context parameters in the actual SQL grammar itself.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-973174010


   > As for the partition, I think an independent PARTITION BY is more flexible. ClickHouse also provides optional PARTITION BY keyword. If it's not specified, data would not be partitioned.
   
   @FrankChen021 It sounds like that PARTITION BY is similar to Druid "segment granularity". I was suggesting we call that "BUCKET BY" but "PARTITION BY" does seem to be more common. To try to figure out what we should do, I did some research into how these things are usually called.
   
   One concept is "splitting the dataset into subsets, where each subset has a _single value_ of a key". This is often used to simplify data management, because it enables rewriting that one partition without touching anything else. It's common for the key to be some time function like hour, day, or month. This is supported by a variety of dbs, although not all of them. It seems like "PARTITION BY" or "PARTITIONED BY" is the most common term:
   
   - Druid: segmentGranularity
   - BigQuery: [PARTITION BY](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#partition_expression)
   - Snowflake: does not appear to offer this
   - Redshift: does not appear to offer this
   - Hive: [PARTITIONED BY](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable)
   - Spark SQL: [PARTITIONED BY](https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.html)
   
   Another concept is "colocating data with same or similar values of a key". This is used to improve compression and query performance. It's supported by every db I checked.
   
   - Druid: partitionsSpec
   - BigQuery: [CLUSTER BY](https://cloud.google.com/bigquery/docs/creating-clustered-tables)
   - Snowflake: [CLUSTER BY](https://docs.snowflake.com/en/sql-reference/sql/create-table.html)
   - Redshift: [SORTKEY](https://docs.aws.amazon.com/redshift/latest/dg/t_Sorting_data.html)
   - Hive: [CLUSTERED BY](https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable)
   - Spark SQL: [CLUSTERED BY](https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.html)
   
   With all this in mind it seems like the most conventional language would be PARTITION BY for segment granularity and CLUSTER BY for secondary partitioning. Meaning the query would look like:
   
   ```sql
   INSERT INTO tbl
   SELECT ...
   FROM ...
   PARTITION BY FLOOR(__time TO DAY)
   CLUSTER BY channel
   ```
   
   I think there is some risk here of confusion with "PARTITION BY" vs. Druid's "partitionsSpec" ingestion config, which also uses the word "partition" but refers more to the "clustering" concept. But I could believe this is fine for the sake of having the SQL language be more aligned with other DBs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on issue #11929: Batch ingestion using SQL INSERT

Posted by GitBox <gi...@apache.org>.
gianm commented on issue #11929:
URL: https://github.com/apache/druid/issues/11929#issuecomment-974489529


   Updated the proposal to include some of the stuff we've been talking about: PARTITION BY, CLUSTER BY, and friendlier alternatives to EXTERN.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org