Skip to content

Commit

Permalink
clickhouse: specialize Date json extract
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Feb 12, 2024
1 parent 2ab1609 commit fea4450
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))

Check failure on line 165 in flow/connectors/clickhouse/normalize.go

View workflow job for this annotation

GitHub Actions / lint

line is 150 characters (lll)
} 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 fea4450

Please sign in to comment.