Skip to content

Commit

Permalink
not sure why exists is uint8 instead of bool, but ok
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Oct 12, 2024
1 parent 8297d83 commit 441bc75
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flow/connectors/clickhouse/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connclickhouse

import (
"context"
"errors"
"fmt"
"log/slog"
"strings"
Expand All @@ -28,7 +29,7 @@ func (c *ClickHouseConnector) getRawTableName(flowJobName string) string {

func (c *ClickHouseConnector) checkIfTableExists(ctx context.Context, databaseName string, tableIdentifier string) (bool, error) {
// TODO escape
var existsC chproto.ColBool
var existsC chproto.ColUInt8
if err := c.query(ctx, ch.Query{
Body: fmt.Sprintf(checkIfTableExistsSQL, "'"+databaseName+"'", "'"+tableIdentifier+"'"),
Result: chproto.Results{
Expand All @@ -38,12 +39,15 @@ func (c *ClickHouseConnector) checkIfTableExists(ctx context.Context, databaseNa
if block.Rows != 1 {
return fmt.Errorf("[clickhouse] checkIfTableExists: expected 1 row, got %d", block.Rows)
}
if block.Info.Overflows {
return errors.New("[clickhouse] checkIfTableExists: expected 1 row, got block with overflow")
}
return nil
},
}); err != nil {
return false, fmt.Errorf("error while reading result row: %w", err)
}
return existsC[0], nil
return existsC[0] != 0, nil
}

func (c *ClickHouseConnector) CreateRawTable(ctx context.Context, req *protos.CreateRawTableInput) (*protos.CreateRawTableOutput, error) {
Expand Down

0 comments on commit 441bc75

Please sign in to comment.