forked from github/gh-ost
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tim Vaillancourt <[email protected]>
- Loading branch information
1 parent
59fd18d
commit 67fd2a2
Showing
7 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package sql | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
type OptimizerHints struct { | ||
ResourceGroup string `hint:"RESOURCE_GROUP"` | ||
MaxExecutionTime int `hint:"MAX_EXECUTION_TIME"` | ||
} | ||
|
||
func (oh OptimizerHints) String() (comment string) { | ||
ts := reflect.TypeOf(oh) | ||
if ts.NumField() == 0 { | ||
return comment | ||
} | ||
|
||
vs := reflect.ValueOf(oh) | ||
hintSlice := make([]string, 0, ts.NumField()) | ||
for i := 0; i < ts.NumField(); i++ { | ||
fieldTag := ts.Field(i).Tag | ||
value := vs.Field(i) | ||
if hint, ok := fieldTag.Lookup("hint"); ok && !value.IsZero() { | ||
switch value.Kind() { | ||
case reflect.String: | ||
hintSlice = append(hintSlice, fmt.Sprintf(`%s(%s)`, hint, value.String())) | ||
default: | ||
hintSlice = append(hintSlice, fmt.Sprintf(`%s(%d)`, hint, value.Int())) | ||
} | ||
} | ||
} | ||
|
||
if len(hintSlice) > 0 { | ||
comment = fmt.Sprintf(`/*+ %s */`, strings.Join(hintSlice, " ")) | ||
} | ||
return comment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
test "github.com/openark/golib/tests" | ||
) | ||
|
||
func TestOptimizerHintsString(t *testing.T) { | ||
hints := OptimizerHints{ | ||
ResourceGroup: t.Name(), | ||
MaxExecutionTime: 1000, | ||
} | ||
test.S(t).ExpectEquals(hints.String(), `/*+ RESOURCE_GROUP(`+t.Name()+`) MAX_EXECUTION_TIME(1000) */`) | ||
} |