Skip to content

Commit

Permalink
Schema DDL: separate redshift-specific code from standard SQL (Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
szareiangm committed Jun 28, 2018
1 parent d66ffea commit 86fcf7d
Show file tree
Hide file tree
Showing 35 changed files with 783 additions and 577 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.iglu.schemaddl.redshift
package com.snowplowanalytics.iglu.schemaddl
package redshift

/**
* column_attributes are:
* [ DEFAULT default_expr ]
* [ IDENTITY ( seed, step ) ]
* [ ENCODE encoding ]
* [ DISTKEY ]
* [ SORTKEY ]
*/
sealed trait ColumnAttribute extends Ddl

case class Default(value: String) extends ColumnAttribute {
def toDdl = s"DEFAULT $value"
}
import sql.{ColumnAttribute, Ddl}

case class Identity(seed: Int, step: Int) extends ColumnAttribute {
def toDdl = s"IDENTITY ($seed, $step)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,17 @@
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.iglu.schemaddl.redshift
package com.snowplowanalytics.iglu.schemaddl
package redshift

import sql.DataType

/**
* Data types
* http://docs.aws.amazon.com/redshift/latest/dg/c_Supported_data_types.html
*/
sealed trait DataType extends Ddl

case object RedshiftTimestamp extends DataType {
def toDdl = "TIMESTAMP"
}

case object RedshiftDate extends DataType {
def toDdl = "DATE"
}

case object RedshiftSmallInt extends DataType {
def toDdl = "SMALLINT"
}

case object RedshiftInteger extends DataType {
def toDdl = "INT"
}

case object RedshiftBigInt extends DataType {
def toDdl = "BIGINT"
}

case object RedshiftReal extends DataType {
def toDdl = "REAL"
}

case object RedshiftDouble extends DataType {
def toDdl = "DOUBLE PRECISION"
}

case class RedshiftDecimal(precision: Option[Int], scale: Option[Int]) extends DataType {
def toDdl = (precision, scale) match {
case (Some(p), Some(s)) => s"DECIMAL ($p, $s)"
case _ => "DECIMAL"
}
}

case object RedshiftBoolean extends DataType {
def toDdl = "BOOLEAN"
}

case class RedshiftVarchar(size: Int) extends DataType {
def toDdl = s"VARCHAR($size)"
}

case class RedshiftChar(size: Int) extends DataType {
def toDdl = s"CHAR($size)"
}

// CUSTOM

/**
* These predefined data types assembles into usual Redshift data types, but
* can store additional information such as warnings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ package com.snowplowanalytics.iglu.schemaddl.redshift
// Scalaz
import scalaz.NonEmptyList

// This project
import com.snowplowanalytics.iglu.schemaddl.sql.Ddl
import com.snowplowanalytics.iglu.schemaddl.sql.TableAttribute

/**
* table_attributes are:
* [ DISTSTYLE { EVEN | KEY | ALL } ]
* [ DISTKEY ( column_name ) ]
* [ [COMPOUND | INTERLEAVED ] SORTKEY ( column_name [, ...] ) ]
*/
sealed trait TableAttribute extends Ddl

sealed trait DiststyleValue extends Ddl
case object Even extends DiststyleValue { def toDdl = "EVEN" }
Expand Down
Loading

0 comments on commit 86fcf7d

Please sign in to comment.