Skip to content

Commit

Permalink
Merge pull request pingcap#8 from crazycs520/regine-table-schema
Browse files Browse the repository at this point in the history
regine table column type
  • Loading branch information
crazycs520 authored Jan 6, 2022
2 parents 0194b7b + 7c32614 commit 637739d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion interval/athena/athena.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/athena"
"github.com/pingcap/tidb/dumpling/context"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -230,7 +231,8 @@ func buildCreateTableSQL(table string, s3BucketName string, tbInfo *model.TableI
buf.WriteString(", ")
}
writeKey(buf, col.Name.L)
buf.WriteString(" string")
buf.WriteString(" ")
buf.WriteString(getColumnType(col))
}
buf.WriteString(" ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' ")
buf.WriteString(" OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' ")
Expand All @@ -240,6 +242,27 @@ func buildCreateTableSQL(table string, s3BucketName string, tbInfo *model.TableI
return buf.String()
}

func getColumnType(col *model.ColumnInfo) string {
switch col.Tp {
case mysql.TypeTiny:
return "TINYINT"
case mysql.TypeShort:
return "SMALLINT"
case mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
return "BIGINT"
case mysql.TypeTimestamp:
return "VARCHAR(64)"
case mysql.TypeDouble, mysql.TypeFloat, mysql.TypeNewDecimal:
return col.FieldType.String()
case mysql.TypeVarchar:
return fmt.Sprintf("VARCHAR(%d)", col.FieldType.Flen)
case mysql.TypeYear:
return "BIGINT"
default:
return "STRING"
}
}

func writeKey(buf *bytes.Buffer, name string) {
buf.WriteByte('`')
buf.WriteString(name)
Expand Down

0 comments on commit 637739d

Please sign in to comment.