Skip to content

Commit ddba45b

Browse files
committed
Schema DDL: separate redshift-specific code from standard SQL (Closes #372)
1 parent d66ffea commit ddba45b

35 files changed

+795
-574
lines changed

0-common/schema-ddl/src/main/scala/com.snowplowanalytics/iglu.schemaddl/redshift/ColumnAttribute.scala

+3-14
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,10 @@
1010
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1212
*/
13-
package com.snowplowanalytics.iglu.schemaddl.redshift
13+
package com.snowplowanalytics.iglu.schemaddl
14+
package redshift
1415

15-
/**
16-
* column_attributes are:
17-
* [ DEFAULT default_expr ]
18-
* [ IDENTITY ( seed, step ) ]
19-
* [ ENCODE encoding ]
20-
* [ DISTKEY ]
21-
* [ SORTKEY ]
22-
*/
23-
sealed trait ColumnAttribute extends Ddl
24-
25-
case class Default(value: String) extends ColumnAttribute {
26-
def toDdl = s"DEFAULT $value"
27-
}
16+
import sql.{ColumnAttribute, Ddl}
2817

2918
case class Identity(seed: Int, step: Int) extends ColumnAttribute {
3019
def toDdl = s"IDENTITY ($seed, $step)"

0-common/schema-ddl/src/main/scala/com.snowplowanalytics/iglu.schemaddl/redshift/DataType.scala

+4-50
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,17 @@
1010
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1212
*/
13-
package com.snowplowanalytics.iglu.schemaddl.redshift
13+
package com.snowplowanalytics.iglu.schemaddl
14+
package redshift
15+
16+
import sql.DataType
1417

1518
/**
1619
* Data types
1720
* http://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html
1821
*/
19-
sealed trait DataType extends Ddl
20-
21-
case object RedshiftTimestamp extends DataType {
22-
def toDdl = "TIMESTAMP"
23-
}
24-
25-
case object RedshiftDate extends DataType {
26-
def toDdl = "DATE"
27-
}
28-
29-
case object RedshiftSmallInt extends DataType {
30-
def toDdl = "SMALLINT"
31-
}
32-
33-
case object RedshiftInteger extends DataType {
34-
def toDdl = "INT"
35-
}
36-
37-
case object RedshiftBigInt extends DataType {
38-
def toDdl = "BIGINT"
39-
}
40-
41-
case object RedshiftReal extends DataType {
42-
def toDdl = "REAL"
43-
}
44-
45-
case object RedshiftDouble extends DataType {
46-
def toDdl = "DOUBLE PRECISION"
47-
}
48-
49-
case class RedshiftDecimal(precision: Option[Int], scale: Option[Int]) extends DataType {
50-
def toDdl = (precision, scale) match {
51-
case (Some(p), Some(s)) => s"DECIMAL ($p, $s)"
52-
case _ => "DECIMAL"
53-
}
54-
}
55-
56-
case object RedshiftBoolean extends DataType {
57-
def toDdl = "BOOLEAN"
58-
}
59-
60-
case class RedshiftVarchar(size: Int) extends DataType {
61-
def toDdl = s"VARCHAR($size)"
62-
}
63-
64-
case class RedshiftChar(size: Int) extends DataType {
65-
def toDdl = s"CHAR($size)"
66-
}
6722

6823
// CUSTOM
69-
7024
/**
7125
* These predefined data types assembles into usual Redshift data types, but
7226
* can store additional information such as warnings.

0-common/schema-ddl/src/main/scala/com.snowplowanalytics/iglu.schemaddl/redshift/TableAttribute.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
package com.snowplowanalytics.iglu.schemaddl.redshift
1414

1515
// Scalaz
16+
import com.snowplowanalytics.iglu.schemaddl.sql.TableAttribute
1617
import scalaz.NonEmptyList
1718

19+
// This project
20+
import com.snowplowanalytics.iglu.schemaddl.sql.Ddl
21+
22+
1823
/**
1924
* table_attributes are:
2025
* [ DISTSTYLE { EVEN | KEY | ALL } ]
2126
* [ DISTKEY ( column_name ) ]
2227
* [ [COMPOUND | INTERLEAVED ] SORTKEY ( column_name [, ...] ) ]
2328
*/
24-
sealed trait TableAttribute extends Ddl
2529

2630
sealed trait DiststyleValue extends Ddl
2731
case object Even extends DiststyleValue { def toDdl = "EVEN" }

0 commit comments

Comments
 (0)