-
Notifications
You must be signed in to change notification settings - Fork 26
/
tableid.go
50 lines (40 loc) · 1.13 KB
/
tableid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package bigquery
import (
"fmt"
"github.com/artie-labs/transfer/lib/destination/types"
"github.com/artie-labs/transfer/lib/sql"
)
var dialect = sql.BigQueryDialect{}
type TableIdentifier struct {
projectID string
dataset string
table string
}
func NewTableIdentifier(projectID, dataset, table string) TableIdentifier {
return TableIdentifier{
projectID: projectID,
dataset: dataset,
table: table,
}
}
func (ti TableIdentifier) ProjectID() string {
return ti.projectID
}
func (ti TableIdentifier) Dataset() string {
return ti.dataset
}
func (ti TableIdentifier) Table() string {
return ti.table
}
func (ti TableIdentifier) WithTable(table string) types.TableIdentifier {
return NewTableIdentifier(ti.projectID, ti.dataset, table)
}
func (ti TableIdentifier) FullyQualifiedName() string {
// The fully qualified name for BigQuery is: project_id.dataset.tableName.
// We are escaping the project_id, dataset, and table because there could be special characters.
return fmt.Sprintf("%s.%s.%s",
dialect.QuoteIdentifier(ti.projectID),
dialect.QuoteIdentifier(ti.dataset),
dialect.QuoteIdentifier(ti.table),
)
}