<commit_before>---
title: AST
layout: docs
section: docs
---

### The Scoobie AST

The Scoobie AST is a very simple construction of nodes which eventually make up a sql query. If you're looking to build DSLs or just want to understand the AST better, then keep reading.

#### Index

To get around quickly, use the index below.

* [`QueryExpression`](#query-expression)
  * `QuerySelect`
  * `QueryModify`
    * `QueryInsert`
    * `QueryUpdate`
    * `QueryDelete`
* `QueryValue`
  * `QuerySelect`
  * `QueryParameter`
  * `QueryNull`
  * `QueryRawExpression`
  * `QueryFunction`
  * `QueryArithmetic`
    * `QueryAdd`
    * `QuerySub`
    * `QueryDiv`
    * `QueryMul`
  * `QueryPath`
    * `QueryPathCons`
    * `QueryPathEnd`
* `QueryComparison`
  * `QueryComparisonNop`
  * `QueryEqual`
  * `QueryGreaterThan` 
  * `QueryGreaterThanOrEqual`
  * `QueryLessThan`
  * `QueryLessThanOrEqual`
  * `QueryAnd`
  * `QueryOr`
  * `QueryIn`
  * `QueryLit`
  * `QueryNot`
* `QueryProjection`
  * `QueryProjectOne`
  * `QueryProjectAll`
* `QueryJoin`
  * `QueryInnerJoin`
  * `QueryFullOuterJoin`
  * `QueryLeftOuterJoin`
  * `QueryRightOuterJoin`
  * `QueryCrossJoin`
* `QuerySort`
  * `QuerySortAsc`
  * `QuerySortDesc`

### Query Expression

The highest level node that exists in the Scoobie AST is [`QueryExpression`](#query-expression). Where ever you have a [`QueryExpression`](#query-expression), you have a complete and executable query. 
At the same level as [`QueryExpression`](#query-expression) is `QueryModify` and `QuerySelect`. 

* `QuerySelect` exclusively represents Select statements.
* `QueryModify` represents Inserts (`QueryInsert`), Updates (`QueryUpdate`), and Deletes (`QueryDelete`).

#### Query Select

A `QuerySelect` is comprised of 8 parts.
1. a `QueryProjection` representing the table that is being selected from. 
2. a `List[QueryProjection]` of all the datums to be selected.
3. a `List[QueryJoin]` of all the joins to be performed.
4. a `QueryComparison` representing the where/filter clause of a query.
5. a `List[QuerySort]` representing the sort actions.
6. a `List[QuerySort]` representing the groupBy actions.
7. a `Option[Long]` representing the query offset.
8. a `Option[Long]` representing the limit.

All `QuerySelect` values extend [`QueryExpression`](#query-expression) and `QueryValue`. `QuerySelect` extending `QueryValue` has great significance regarding subqueries.

#### Query Update

A `QueryUpdate` is comprised of 3 parts.
1. a `QueryPath` representing the collection to perform the update on.
2. a `List[ModifyField]` representing the fields to be modified and their associated new values.
3. a `QueryComparison` representing the where/filter clause of the update.

All `QueryUpdate` values extend [`QueryExpression`](#query-expression) and `QueryModify`.

#### Query Insert

A `QueryInsert` is comprised of 2 parts. 
1. a `QueryPath` representing the collection to perform the insert on.
2. a `List[ModifyField]` representing the values of each column.

All `QueryInsert` values extend [`QueryExpression`](#query-expression) and `QueryModify`.

#### Query Delete

A `QueryDelete` is comprised of 2 parts.
1. a `QueryPath` representing the collection to perform the delete on.
2. a `QueryComparison` representing the where/filter clause of the delete.

All `QueryDelete` values extends [`QueryExpression`](#query-expression) and `QueryModify`.

#### Modify Field

A `ModifyField` value is comporised of two parts.
1. a `QueryPath` representing the column to be modified.
2. a `QueryValue` representing the value.

`ModifyField` has no sub or super-classes. It's a very specific use case.  It is essentially a specialized tuple which one might view as
```tut:silent
type ModifyField = (QueryPath, QueryValue)
```

It exists only to pair a path with a value. 

### Query Value

A `QueryValue` is the super-type for anything that can be used in a SQL ast in a value position. This means much of the AST extends it. <commit_msg>test link thing.<commit_after>---
title: AST
layout: docs
section: docs
---

### The Scoobie AST

The Scoobie AST is a very simple construction of nodes which eventually make up a sql query. If you're looking to build DSLs or just want to understand the AST better, then keep reading.

#### Index

To get around quickly, use the index below.

* <code><a href="#query-expression">QueryExpression(#query-expression)</a></code>
  * `QuerySelect`
  * `QueryModify`
    * `QueryInsert`
    * `QueryUpdate`
    * `QueryDelete`
* `QueryValue`
  * `QuerySelect`
  * `QueryParameter`
  * `QueryNull`
  * `QueryRawExpression`
  * `QueryFunction`
  * `QueryArithmetic`
    * `QueryAdd`
    * `QuerySub`
    * `QueryDiv`
    * `QueryMul`
  * `QueryPath`
    * `QueryPathCons`
    * `QueryPathEnd`
* `QueryComparison`
  * `QueryComparisonNop`
  * `QueryEqual`
  * `QueryGreaterThan` 
  * `QueryGreaterThanOrEqual`
  * `QueryLessThan`
  * `QueryLessThanOrEqual`
  * `QueryAnd`
  * `QueryOr`
  * `QueryIn`
  * `QueryLit`
  * `QueryNot`
* `QueryProjection`
  * `QueryProjectOne`
  * `QueryProjectAll`
* `QueryJoin`
  * `QueryInnerJoin`
  * `QueryFullOuterJoin`
  * `QueryLeftOuterJoin`
  * `QueryRightOuterJoin`
  * `QueryCrossJoin`
* `QuerySort`
  * `QuerySortAsc`
  * `QuerySortDesc`

### Query Expression

The highest level node that exists in the Scoobie AST is [`QueryExpression`](#query-expression). Where ever you have a [`QueryExpression`](#query-expression), you have a complete and executable query. 
At the same level as [`QueryExpression`](#query-expression) is `QueryModify` and `QuerySelect`. 

* `QuerySelect` exclusively represents Select statements.
* `QueryModify` represents Inserts (`QueryInsert`), Updates (`QueryUpdate`), and Deletes (`QueryDelete`).

#### Query Select

A `QuerySelect` is comprised of 8 parts.
1. a `QueryProjection` representing the table that is being selected from. 
2. a `List[QueryProjection]` of all the datums to be selected.
3. a `List[QueryJoin]` of all the joins to be performed.
4. a `QueryComparison` representing the where/filter clause of a query.
5. a `List[QuerySort]` representing the sort actions.
6. a `List[QuerySort]` representing the groupBy actions.
7. a `Option[Long]` representing the query offset.
8. a `Option[Long]` representing the limit.

All `QuerySelect` values extend [`QueryExpression`](#query-expression) and `QueryValue`. `QuerySelect` extending `QueryValue` has great significance regarding subqueries.

#### Query Update

A `QueryUpdate` is comprised of 3 parts.
1. a `QueryPath` representing the collection to perform the update on.
2. a `List[ModifyField]` representing the fields to be modified and their associated new values.
3. a `QueryComparison` representing the where/filter clause of the update.

All `QueryUpdate` values extend [`QueryExpression`](#query-expression) and `QueryModify`.

#### Query Insert

A `QueryInsert` is comprised of 2 parts. 
1. a `QueryPath` representing the collection to perform the insert on.
2. a `List[ModifyField]` representing the values of each column.

All `QueryInsert` values extend [`QueryExpression`](#query-expression) and `QueryModify`.

#### Query Delete

A `QueryDelete` is comprised of 2 parts.
1. a `QueryPath` representing the collection to perform the delete on.
2. a `QueryComparison` representing the where/filter clause of the delete.

All `QueryDelete` values extends [`QueryExpression`](#query-expression) and `QueryModify`.

#### Modify Field

A `ModifyField` value is comporised of two parts.
1. a `QueryPath` representing the column to be modified.
2. a `QueryValue` representing the value.

`ModifyField` has no sub or super-classes. It's a very specific use case.  It is essentially a specialized tuple which one might view as
```scala
type ModifyField = (QueryPath, QueryValue)
```

It exists only to pair a path with a value. 

### Query Value

A `QueryValue` is the super-type for anything that can be used in a SQL ast in a value position. This means much of the AST extends it. 
{'fraction_non_alphanumeric': 0.10788121789249468, 'fraction_numerical': 0.005262498433780228, 'mean_word_length': 4.535367545076283, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3599401', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2351, 'n_words': 915}