Skip to content

Commit

Permalink
doc/md: add redshift (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored May 21, 2024
1 parent 6d0b2db commit aa0e178
Show file tree
Hide file tree
Showing 19 changed files with 1,590 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Atlas offers additional commands to assist users managing their database migrati
`migrate status`, and more. For more information, see the versioned migration documentation at https://atlasgo.io/versioned/diff.

### Supported databases
MySQL, MariaDB, PostgresSQL, SQLite, TiDB, CockroachDB, SQL Server, ClickHouse.
MySQL, MariaDB, PostgresSQL, SQLite, TiDB, CockroachDB, SQL Server, ClickHouse, Redshift.

[HCL]: https://atlasgo.io/atlas-schema/hcl
[SQL]: https://atlasgo.io/atlas-schema/sql
Expand Down
218 changes: 217 additions & 1 deletion doc/md/atlas-schema/hcl-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1655,4 +1655,220 @@ table "t" {
```

:::info
The `AggregateFunction` and `SimpleAggregateFunction` are complex data types. Therefore, we recommend using a [Dev Database](../../md/concepts//dev.mdx) to normalize these types.
The `AggregateFunction` and `SimpleAggregateFunction` are complex data types. Therefore, we recommend using a [Dev Database](../../md/concepts//dev.mdx) to normalize these types.
:::

## Redshift

### Boolean
The `boolean` and `bool` types allow creating standard SQL boolean columns.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = boolean
}
column "c2" {
# Alias to boolean.
type = bool
}
}
```

### Binary
The `binary_varying`, `varbinary` and `varbyte` types allow creating binary string columns.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = binary_varying(255)
}
column "c2" {
# Alias to binary_varying
type = varbinary(255)
}
column "c3" {
# Alias to binary_varying
type = varbyte(255)
}
}
```

### Date, Time and Interval
Atlas supports the standard Redshift types for creating date, time and interval columns.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = date
}
column "c2" {
# Equals to "time without time zone".
type = time
}
column "c3" {
# Equals to "time with time zone".
type = timetz
}
column "c4" {
# Equals "timestamp without time zone".
type = timestamp
}
column "c5" {
# Equals "timestamp with time zone".
type = timestamptz
}
column "c6" {
type = sql("interval year to month")
}
}
```

### Fixed Point (Decimal)
The `decimal` and `numeric` types are supported for storing exact numeric values. Note that in Redshift the two types are identical.

```hcl
table "t" {
schema = schema.test
column "c1" {
# Equals to numeric.
type = decimal
}
column "c2" {
# Equals to numeric(5).
type = decimal(5)
}
column "c3" {
# Equals to numeric(5,2).
type = decimal(5,2)
}
}
```

### Floating Point (Float)
The `real` and `double_precision` types are supported for storing approximate numeric values.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = real
}
column "c2" {
type = double_precision
}
column "c3" {
type = float(10)
}
column "c4" {
type = float(30)
}
column "c5" {
# Alias to real.
type = float4
}
column "c6" {
# Alias to double_precision.
type = float8
}
}
```

### Integer
The `smallint`, `integer` / `int`, `bigint` types allow creating integer types.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = smallint
}
column "c2" {
type = integer
}
column "c3" {
type = int
}
column "c4" {
type = bigint
}
column "c5" {
# Alias to smallint.
type = int2
}
column "c6" {
# Alias to integer.
type = int4
}
column "c7" {
# Alias to bigint.
type = int8
}
}
```

### String
The `varchar`, `nvarchar`, `char`, `nchar`, `bpchar`, `character_varying`, `character` and `text` types allow creating string columns.

```hcl
table "t" {
schema = schema.test
column "c1" {
# Equals character_varying(256).
type = varchar
}
column "c2" {
# Alias to character_varying(255).
type = varchar(255)
}
column "c3" {
# Equals to character_varying(255).
type = nvarchar(255)
}
column "c4" {
# Equals to char(1).
type = char
}
column "c5" {
# Equals to char(5).
type = nchar(5)
}
column "c6" {
# Alias to character(5).
type = char(5)
}
column "c7" {
# Alias to character(5).
type = bpchar(5)
}
column "c8" {
# Equals to character_varying(256).
type = text
}
}
```

### Other Types

The `hllsketch`, `super`, `geometry` and `geography` types are supported by Atlas.

```hcl
table "t" {
schema = schema.test
column "c1" {
type = hllsketch
}
column "c2" {
type = super
}
column "c3" {
type = geometry
}
column "c4" {
type = geography
}
}
```
109 changes: 109 additions & 0 deletions doc/md/atlas-schema/hcl.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ schema "atomic" {
}
```

</TabItem>
<TabItem value="redshift" label="Redshift">

```hcl
schema "public" {
comment = "A schema comment"
}
schema "private" {}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -230,6 +241,63 @@ table "b" "users" {
}
```

### Distribution

The `distribution` attribute allows for specifying the distribution method of the table.

:::note
Distribution is currently supported only by the Redshift driver. Support for the remaining drivers will be added in future versions.
:::

<Tabs>
<TabItem label="Redshift" value="redshift">

```hcl
table "users" {
schema = schema.public
// highlight-next-line
column "id" {
type = int
}
distribution {
style = KEY // EVEN | ALL | AUTO
key = column.id // only for KEY style
}
}
```

</TabItem>
</Tabs>

### Sorting

The `sort` attribute allows for specifying the sorting method of the table.

:::note
Sorting is currently supported only by the Redshift driver. Support for the remaining drivers will be added in future versions.
:::

<Tabs>
<TabItem label="Redshift" value="redshift">

```hcl
table "users" {
schema = schema.public
// highlight-next-line
column "id" {
type = int
}
sort {
style = COMPOUND // INTERLEAVED | COMPOUND | AUTO
columns = [column.id]
}
}
```

</TabItem>
</Tabs>

## View

A `view` is a virtual table in the database, defined by a statement that queries rows from one or more existing
Expand Down Expand Up @@ -356,6 +424,28 @@ Note that modifying the materialized view structure
after the initial creation is not supported by Atlas currently.
:::

</TabItem>
<TabItem label="Redshift" value="redshift">

```hcl
materialized "mat_view" {
schema = schema.public
column "c1" {
null = true
type = smallint
}
as = "SELECT * FROM t1;"
comment = "example materialized view"
distribution {
style = EVEN
}
sort {
style = AUTO
}
depends_on = [table.t1]
}
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -495,6 +585,25 @@ table "users" {
Note, it is recommended to use the [`--dev-url`](../concepts/dev-database) option when generated columns are used.
:::

### Encodings

Encodings are used to define the compression algorithm for the column data. Supported by ClickHouse and Redshift.

<Tabs>
<TabItem label="Redshift" value="redshift">

```hcl
table "users" {
schema = schema.public
column "name" {
type = text
encode = LZ4 // AZ64 | RAW | LZ4 | ZSTD
}
}
```
</TabItem>
</Tabs>

## Column Types

The SQL dialects supported by Atlas (Postgres, MySQL, MariaDB, and SQLite) vary in
Expand Down
Loading

0 comments on commit aa0e178

Please sign in to comment.