Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema DDL: add support for 'date' format #256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ object StringProperties {
case object Ipv6Format extends Format { val asString = "ipv6" }
case object EmailFormat extends Format { val asString = "email" }
case object DateTimeFormat extends Format { val asString = "date-time" }
case object DateFormat extends Format { val asString = "date" }
case object HostNameFormat extends Format { val asString = "hostname" }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object StringSerializers {
case JString(format) if format == "email" => EmailFormat
case JString(format) if format == "hostname" => HostNameFormat
case JString(format) if format == "date-time" => DateTimeFormat
case JString(format) if format == "date" => DateFormat
case JString(format) => CustomFormat(format)
case x => throw new MappingException("Format must be string")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ case object RedshiftTimestamp extends DataType {
def toDdl = "TIMESTAMP"
}

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

case object RedshiftSmallInt extends DataType {
def toDdl = "SMALLINT"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ object DdlGenerator {
complexEnumSuggestion,
productSuggestion,
timestampSuggestion,
dateSuggestion,
arraySuggestion,
integerSuggestion,
numberSuggestion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ object TypeSuggestions {
case _ => None
}

val dateSuggestion: DataTypeSuggestion = (properties, columnName) =>
(properties.get("type"), properties.get("format")) match {
case(Some(types), Some("date")) if types.contains("string") =>
Some(RedshiftDate)
case _ => None
}

val arraySuggestion: DataTypeSuggestion = (properties, columnName) =>
properties.get("type") match {
case Some(types) if types.contains("array") =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TypeSuggestionsSpec extends Specification { def is = s2"""
recognize string,null maxLength == minLength as CHAR $e4
recognize number with product type $e5
recognize integer with product type $e6
recognize timestamp $e7
recognize full date $e8
"""

def e1 = {
Expand Down Expand Up @@ -55,4 +57,14 @@ class TypeSuggestionsSpec extends Specification { def is = s2"""
val props = Map("type" -> "integer,null")
DdlGenerator.getDataType(props, 16, "somecolumn") must beEqualTo(RedshiftBigInt)
}

def e7 = {
val props = Map("type" -> "string", "format" -> "date-time")
DdlGenerator.getDataType(props, 16, "somecolumn") must beEqualTo(RedshiftTimestamp)
}

def e8 = {
val props = Map("type" -> "string", "format" -> "date")
DdlGenerator.getDataType(props, 16, "somecolumn") must beEqualTo(RedshiftDate)
}
}