Skip to content

Commit 7501da3

Browse files
committed
fix: nil pointer issue in test
1 parent dda3480 commit 7501da3

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

cmd/substreams-sink-sql/from_proto_generate_csv_comprehensive_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ func TestCompleteIntegration(t *testing.T) {
685685
var logger = zap.NewNop()
686686

687687
// createSimpleFieldDescriptor creates a basic field descriptor for testing
688+
var testFDSeq int
689+
688690
func createSimpleFieldDescriptor(name string, fieldType descriptor.FieldDescriptorProto_Type) *desc.FieldDescriptor {
689691
fdp := &descriptor.FieldDescriptorProto{
690692
Name: &name,
@@ -697,7 +699,8 @@ func createSimpleFieldDescriptor(name string, fieldType descriptor.FieldDescript
697699
Field: []*descriptor.FieldDescriptorProto{fdp},
698700
}
699701

700-
fileName := "test.proto"
702+
testFDSeq++
703+
fileName := fmt.Sprintf("test_%s_%d.proto", name, testFDSeq)
701704
fdProto := &descriptor.FileDescriptorProto{
702705
Name: &fileName,
703706
MessageType: []*descriptor.DescriptorProto{mdp},

db_proto/sql/click_house/dialect.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,17 @@ func tableName(schemaName string, tableName string) string {
227227
}
228228

229229
func orderByString(table *schema.Table) (string, error) {
230-
info := table.PbTableInfo.ClickhouseTableOptions
231-
if info == nil {
232-
// Default to ordering by primary key if available, otherwise by block_number
233-
if table.PrimaryKey != nil {
234-
return fmt.Sprintf("ORDER BY (%s)", table.PrimaryKey.Name), nil
235-
}
236-
return fmt.Sprintf("ORDER BY (%s)", sql2.DialectFieldBlockNumber), nil
237-
}
230+
var info *pbSchema.ClickhouseTableOptions
231+
if table.PbTableInfo != nil {
232+
info = table.PbTableInfo.ClickhouseTableOptions
233+
}
234+
if info == nil {
235+
// Default to ordering by primary key if available, otherwise by block_number
236+
if table.PrimaryKey != nil {
237+
return fmt.Sprintf("ORDER BY (%s)", table.PrimaryKey.Name), nil
238+
}
239+
return fmt.Sprintf("ORDER BY (%s)", sql2.DialectFieldBlockNumber), nil
240+
}
238241

239242
if len(info.OrderByFields) == 0 {
240243
return "", fmt.Errorf("clickhouse table options for table %q don't have any 'order_by_fields'. Require at least 1", table.Name)
@@ -256,11 +259,14 @@ func orderByString(table *schema.Table) (string, error) {
256259
}
257260

258261
func partitionByString(table *schema.Table) (string, error) {
259-
info := table.PbTableInfo.ClickhouseTableOptions
260-
if info == nil {
261-
// Default to partitioning by month based on block timestamp
262-
return fmt.Sprintf("PARTITION BY (%s)", wrapWithClickhouseFunction(sql2.DialectFieldBlockTimestamp, pbSchema.Function_toYYYYMM)), nil
263-
}
262+
var info *pbSchema.ClickhouseTableOptions
263+
if table.PbTableInfo != nil {
264+
info = table.PbTableInfo.ClickhouseTableOptions
265+
}
266+
if info == nil {
267+
// Default to partitioning by month based on block timestamp
268+
return fmt.Sprintf("PARTITION BY (%s)", wrapWithClickhouseFunction(sql2.DialectFieldBlockTimestamp, pbSchema.Function_toYYYYMM)), nil
269+
}
264270

265271
var parts []string
266272

@@ -288,11 +294,14 @@ func partitionByString(table *schema.Table) (string, error) {
288294
}
289295

290296
func replacingMergeTreeString(table *schema.Table) (string, error) {
291-
info := table.PbTableInfo.ClickhouseTableOptions
292-
if info == nil {
293-
// Default to just using version field when no ClickHouse options are set
294-
return fmt.Sprintf("ReplacingMergeTree(%s)", sql2.DialectFieldVersion), nil
295-
}
297+
var info *pbSchema.ClickhouseTableOptions
298+
if table.PbTableInfo != nil {
299+
info = table.PbTableInfo.ClickhouseTableOptions
300+
}
301+
if info == nil {
302+
// Default to just using version field when no ClickHouse options are set
303+
return fmt.Sprintf("ReplacingMergeTree(%s)", sql2.DialectFieldVersion), nil
304+
}
296305

297306
out := sql2.DialectFieldVersion
298307
for _, field := range info.ReplacingFields {

0 commit comments

Comments
 (0)