Skip to content

Conversation

wackywendell
Copy link
Contributor

What does this PR do? What is the motivation?

This clarifies some of the DDSQL editor language features to improve precision.

Merge instructions

  • Please merge after reviewing

Additional notes

@@ -8,7 +8,7 @@ DDSQL is in private beta.

## Overview

DDSQL is a query language for Datadog data. It implements several standard SQL functions, such as `SELECT`, and allows queries against unstructured data, such as [tags][1].
DDSQL is a query language for Datadog data. It implements several standard SQL operations, such as `SELECT`, and allows queries against unstructured data, such as [tags][1].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SELECT is a statement, not a function; in SQL, a function is of the form function_name(args, …). "operation" is a more general term encompassing both.

@@ -8,16 +8,15 @@ DDSQL is in private beta.

## Data types

DDSQL implements a simplified version of the SQL type system that is mostly descended from SQLite.
DDSQL implements a simplified version of the SQL type system that is mostly descended from PostgreSQL.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it may bear similarities to the SQLite type system, SQLite is a dynamically typed SQL, and DDSQL is statically typed. Both historically and currently, DDSQL adheres to PostgreSQL where possible.

| text | char, varchar, json | Storage is always unlimited-length UTF-8. |
| real | double | Storage is always IEEE-754 float64. |
| real | double, decimal | Storage is always IEEE-754 float64. |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DDSQL, decimal is an alias of real, not a separate type.

[2]: https://www.postgresql.org/docs/current/functions-comparison.html

## CASE
Copy link
Contributor Author

@wackywendell wackywendell Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While CASE and CAST begin with keywords like a statement or clause, they are technically expressions in SQL - they can be used as (or inside) the expressions placeholder in the syntax described under SELECT in the "Statements" page.

Note that this block has been moved without modification to expressions and operators.

[ FROM rel_source EVENT_SEARCH 'some message' USE EVENT_INDEX 'index_name'
[ JOIN_TYPE rel_source ... [ ON condition | USING (column, ... ) ] ] ... ]
[ WHERE condition ]
[ FROM rel_source
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several changes here:

  1. EVENT_SEARCH and USE EVENT_INDEX are both separably optional, so additional [ ] are added. e.g. FROM t WHERE …, FROM t EVENT_SEARCH 'x', and FROM t USE EVENT_INDEX 'y' are all valid.
  2. join_type below is described as INNER, OUTER, LEFT, or RIGHT, but the keyword JOIN was missing; that keyword is required.
  3. I indented the JOIN clause under the FROM one, to indicate that it can only be used with (and immediately following) a FROM clause.


`JOIN_TYPE`
`join_type`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to lower-case, as this is a placeholder, not a keyword. The syntax above uses all-caps for keywords and lower-case for placeholders, so I'm aligning with that.

@@ -8,9 +8,11 @@ DDSQL is in private beta.

Tags are a widespread mechanism to encode metadata about a particular record across several products at Datadog. Tags are key-value pairs for which a key may contain multiple values.

Tags are modeled in DDSQL with the key as a column name, and values in a `group` type, a sorted set of strings with tag-like "= is contains" semantics.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The group type is mentioned under "Data Types", so I thought it made sense to be clear about that type here.

## Equality comparisons

Equality comparisons with tags are treated as a "contains" comparison rather than requiring strict equality. `service='website'` is true if a record has a `service` tag with the value `website`, even if it has other service tags as well.
Equality comparisons between tags and strings are treated as a "contains" comparison rather than requiring strict equality. `service='website'` is true if a record has a `service` tag with the value `website`, even if it has other service tags as well.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to clarify that the "contains" behavior applies specifically to equality between tags and strings; as noted in the following section, equality between tags and tags (e.g. group1 = group2) is strict equality.

While these phrases use keywords like statements or clauses, both are used as expressions in SQL statements: they are useable in SELECT, WHERE, and other places expressions are used, and can also be nested with other expressions.
@wackywendell wackywendell force-pushed the wendell/ddsql-clarifications branch from 936285e to 4adc507 Compare August 1, 2024 17:16
@wackywendell wackywendell marked this pull request as ready for review August 1, 2024 17:55
@wackywendell wackywendell requested a review from a team as a code owner August 1, 2024 17:55
@cswatt cswatt added the editorial review Waiting on a more in-depth review label Aug 1, 2024
@cswatt
Copy link
Contributor

cswatt commented Aug 1, 2024

Added DOCS-8607 to track review.

@estherk15 estherk15 merged commit 17c3255 into master Aug 3, 2024
17 checks passed
@estherk15 estherk15 deleted the wendell/ddsql-clarifications branch August 3, 2024 13:31
rtrieu pushed a commit that referenced this pull request Sep 3, 2024
* [ddsql_editor] Some clarifications on DDSQL types and statements

* [ddsql_editor] Moved CAST and CASE from statements to expressions

While these phrases use keywords like statements or clauses, both are used as expressions in SQL statements: they are useable in SELECT, WHERE, and other places expressions are used, and can also be nested with other expressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial review Waiting on a more in-depth review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants