Skip to content

Commit

Permalink
Merge pull request #67 from dremio/65-new-table-file-names-break-wind…
Browse files Browse the repository at this point in the history
…ows-collection

fixed file names for windows
  • Loading branch information
mxmarg authored Jun 21, 2023
2 parents 9531526 + 167f47b commit 3d87512
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/local/apicollect/system_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ func retrieveJobResults(c *conf.CollectConf, jobresultsurl string, headers map[s
simplelog.Warningf("returned json does not contain expected field 'rowCount'")
}
sb := string(body)

filename := "sys." + strings.Replace(systable, "\\\"", "", -1) + urlsuffix + ".json"
filename := getSystemTableName(systable, urlsuffix)
systemTableFile := path.Join(c.SystemTablesOutDir(), filename)
simplelog.Debugf("Creating " + filename + " ...")
file, err := os.Create(path.Clean(systemTableFile))
Expand All @@ -185,5 +184,15 @@ func retrieveJobResults(c *conf.CollectConf, jobresultsurl string, headers map[s
}

return nil
}

func getSystemTableName(systable, urlsuffix string) string {
filename := strings.Join([]string{"sys.", systable, urlsuffix, ".json"}, "")
// the ? will not work on windows
filename = strings.Replace(filename, "?", "_", -1)
// the = will not work on windows
filename = strings.Replace(filename, "=", "_", -1)
// go ahead and remove & because it will look weird by itself in the file name
filename = strings.Replace(filename, "&", "_", -1)
return strings.Replace(filename, "\\\"", "", -1)
}
58 changes: 58 additions & 0 deletions cmd/local/apicollect/system_tables_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2023 Dremio Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// apicollect provides all the methods that collect via the API, this is a substantial part of the activities of DDC so it gets it's own package
package apicollect

import "testing"

func TestSysTableNameWithNoEscapableCharacters(t *testing.T) {
urlsuffix := ""

name := getSystemTableName("thing", urlsuffix)
expected := "sys.thing.json"
if name != expected {
t.Errorf("expected %v but was %v", expected, name)
}
}

func TestSysTableNameWithBackslashAndDoubleQuotes(t *testing.T) {
urlsuffix := ""

name := getSystemTableName("\\\"thing\\\"", urlsuffix)
expected := "sys.thing.json"
if name != expected {
t.Errorf("expected %v but was %v", expected, name)
}
}

func TestSysTableNameWithQuestionMarkAndEqualsCharacters(t *testing.T) {
urlsuffix := "?offset=0"

name := getSystemTableName("thing", urlsuffix)
expected := "sys.thing_offset_0.json"
if name != expected {
t.Errorf("expected %v but was %v", expected, name)
}
}

func TestSysTableNameWithAllEscapableCharacters(t *testing.T) {
urlsuffix := "?offset=0&limit=500"

name := getSystemTableName("\\\"tables\\\"", urlsuffix)
expected := "sys.tables_offset_0_limit_500.json"
if name != expected {
t.Errorf("expected %v but was %v", expected, name)
}
}

0 comments on commit 3d87512

Please sign in to comment.