Skip to content

Commit

Permalink
clickhouse: specialize Date json extract (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored Feb 12, 2024
1 parent 54799e1 commit 69b5d33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flow/connectors/clickhouse/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,16 @@ func (c *ClickhouseConnector) NormalizeRecords(ctx context.Context, req *model.N
clickhouseType = "String"
}

projection.WriteString(fmt.Sprintf("JSONExtract(_peerdb_data, '%s', '%s') AS `%s`,", cn, clickhouseType, cn))
if clickhouseType == "Date" {
projection.WriteString(fmt.Sprintf("toDate(parseDateTime64BestEffortOrNull(JSONExtractString(_peerdb_data, '%s'))) AS `%s`,", cn, cn))
} else {
projection.WriteString(fmt.Sprintf("JSONExtract(_peerdb_data, '%s', '%s') AS `%s`,", cn, clickhouseType, cn))
}
}

// add _peerdb_sign as _peerdb_record_type / 2
projection.WriteString(fmt.Sprintf("intDiv(_peerdb_record_type, 2) AS `%s`,", signColName))
colSelector.WriteString(fmt.Sprintf("%s,", signColName))
colSelector.WriteString(fmt.Sprintf("`%s`,", signColName))

// add _peerdb_timestamp as _peerdb_version
projection.WriteString(fmt.Sprintf("_peerdb_timestamp AS `%s`", versionColName))
Expand Down

0 comments on commit 69b5d33

Please sign in to comment.