@@ -3,18 +3,17 @@ package main
33import (
44 "context"
55 "fmt"
6- "github.com/odpf/optimus/run"
76 "reflect"
87 "sort"
98 "testing"
109 "time"
1110
11+ "cloud.google.com/go/bigquery"
12+ "github.com/googleapis/google-cloud-go-testing/bigquery/bqiface"
1213 "github.com/odpf/optimus/models"
14+ "github.com/odpf/optimus/run"
1315 "github.com/patrickmn/go-cache"
1416 "github.com/stretchr/testify/assert"
15-
16- "cloud.google.com/go/bigquery"
17- "github.com/googleapis/google-cloud-go-testing/bigquery/bqiface"
1817 "github.com/stretchr/testify/mock"
1918)
2019
@@ -148,13 +147,13 @@ func TestBQ2BQ(t *testing.T) {
148147 scheduledAt := time .Date (2021 , 1 , 15 , 2 , 2 , 2 , 2 , time .UTC )
149148 t .Run ("should not compile assets if load method is not replace" , func (t * testing.T ) {
150149 compileRequest := models.CompileAssetsRequest {
151- Config : models.PluginConfigs {
150+ Config : models.PluginConfigs {
152151 {
153152 Name : "LOAD_METHOD" ,
154153 Value : "MERGE" ,
155154 },
156155 },
157- Assets : models.PluginAssets {
156+ Assets : models.PluginAssets {
158157 {
159158 Name : "query.sql" ,
160159 Value : `Select * from table where ts > "{{.DSTART}}"` ,
@@ -167,27 +166,27 @@ func TestBQ2BQ(t *testing.T) {
167166 resp , err := b2b .CompileAssets (ctx , compileRequest )
168167 assert .Nil (t , err )
169168 assert .NotNil (t , resp )
170- compAsset , _ := compileRequest .Assets .Get ("query.sql" )
171- respAsset , _ := resp .Assets .Get ("query.sql" )
169+ compAsset , _ := compileRequest .Assets .Get ("query.sql" )
170+ respAsset , _ := resp .Assets .Get ("query.sql" )
172171 assert .Equal (t , compAsset .Value , respAsset .Value )
173172 })
174173 t .Run ("should not compile assets if load method is replace but window size is less than equal partition delta" , func (t * testing.T ) {
175174 compileRequest := models.CompileAssetsRequest {
176- PluginOptions : models.PluginOptions {
175+ PluginOptions : models.PluginOptions {
177176 DryRun : false ,
178177 },
179- Config : models.PluginConfigs {
178+ Config : models.PluginConfigs {
180179 {
181180 Name : "LOAD_METHOD" ,
182181 Value : "REPLACE" ,
183182 },
184183 },
185- Window : models.JobSpecTaskWindow {
184+ Window : models.JobSpecTaskWindow {
186185 Size : time .Hour * 24 ,
187186 Offset : 0 ,
188187 TruncateTo : "w" ,
189188 },
190- Assets : models.PluginAssets {
189+ Assets : models.PluginAssets {
191190 {
192191 Name : "query.sql" ,
193192 Value : `Select * from table where ts > "{{.DSTART}}"` ,
@@ -203,26 +202,26 @@ func TestBQ2BQ(t *testing.T) {
203202 assert .Nil (t , err )
204203 assert .NotNil (t , resp )
205204 compAsset , _ := compileRequest .Assets .Get ("query.sql" )
206- respAsset , _ := resp .Assets .Get ("query.sql" )
205+ respAsset , _ := resp .Assets .Get ("query.sql" )
207206 assert .Equal (t , compAsset .Value , respAsset .Value )
208207 })
209208 t .Run ("should compile assets if load method is replace and break the query into multiple parts" , func (t * testing.T ) {
210209 compileRequest := models.CompileAssetsRequest {
211- PluginOptions : models.PluginOptions {
210+ PluginOptions : models.PluginOptions {
212211 DryRun : false ,
213212 },
214- Config : models.PluginConfigs {
213+ Config : models.PluginConfigs {
215214 {
216215 Name : "LOAD_METHOD" ,
217216 Value : "REPLACE" ,
218217 },
219218 },
220- Window : models.JobSpecTaskWindow {
219+ Window : models.JobSpecTaskWindow {
221220 Size : time .Hour * 24 * 7 ,
222221 Offset : 0 ,
223222 TruncateTo : "w" ,
224223 },
225- Assets : models.PluginAssets {
224+ Assets : models.PluginAssets {
226225 {
227226 Name : "query.sql" ,
228227 Value : `Select * from table where ts > "{{.DSTART}}"` ,
@@ -250,7 +249,7 @@ Select * from table where ts > "2021-01-14T00:00:00Z"
250249Select * from table where ts > "2021-01-15T00:00:00Z"
251250--*--optimus-break-marker--*--
252251Select * from table where ts > "2021-01-16T00:00:00Z"`
253- respAsset , _ := resp .Assets .Get ("query.sql" )
252+ respAsset , _ := resp .Assets .Get ("query.sql" )
254253 assert .Equal (t , compAsset , respAsset .Value )
255254 })
256255
@@ -318,6 +317,12 @@ Select * from table where ts > "2021-01-16T00:00:00Z"`
318317 Sources : newSet ("data-engineering.testing.table1" ),
319318 Ignored : newSet (),
320319 },
320+ {
321+ Name : "simple query with hyphenated table name" ,
322+ Query : "select * from data-engineering.testing.table_name-1" ,
323+ Sources : newSet ("data-engineering.testing.table_name-1" ),
324+ Ignored : newSet (),
325+ },
321326 {
322327 Name : "simple query with quotes" ,
323328 Query : "select * from `data-engineering.testing.table1`" ,
0 commit comments