Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup whitespace and comments in SQL query text #1246

Merged
merged 8 commits into from
Dec 8, 2023

Conversation

timvaillancourt
Copy link
Collaborator

@timvaillancourt timvaillancourt commented Jan 11, 2023

Description

This PR cleans up SQL query text in several files where whitespace, line separation and the use of comments were inconsistent

The rules I followed were:

  1. All queries include a /* gh-ost */ or /* gh-ost database.table */ comment
  2. Single-tabs (/t) are used for indentation
  3. Queries are defined as the variable query := using backticks
  4. SQL begins on the line following query after a single tab
    • Example:
      query := `
              select /* gh-ost */
              ...`
    • Exception: simple var-only queries without a FROM, example: select /* gh-ost */ @@global.log_slave_updates
  5. SQL is further indented when these terms are encountered:
    • FROM/INTO
    • SET/ON DUPLICATE KEY UPDATE
    • VALUES
    • WHERE
    • ( or ) SQL-block brackets, example: a sub-query
    • INNER JOIN
    • ON
    • CASE
  6. No newline at end of query var / close backtick after last word

What this PR does NOT address is the inconsistency in capitalization in SQL. I would like to leave this to a vote from the community in an up-coming GitHub Discussion, and I will follow-up on this separately

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

@timvaillancourt timvaillancourt marked this pull request as ready for review January 11, 2023 22:47
@timvaillancourt timvaillancourt changed the title Cleanup whitespace in SQL query text Cleanup whitespace and comments in SQL query text Jan 11, 2023
@timvaillancourt timvaillancourt added this to the v1.1.7 milestone Dec 7, 2023
@meiji163
Copy link
Contributor

meiji163 commented Dec 8, 2023

looks nice!

meiji163
meiji163 previously approved these changes Dec 8, 2023
Signed-off-by: Tim Vaillancourt <[email protected]>
@timvaillancourt timvaillancourt merged commit 5ebb953 into github:master Dec 8, 2023
7 checks passed
@timvaillancourt timvaillancourt deleted the fix-sql-whitespace branch December 8, 2023 23:30
RainbowDashy pushed a commit to bytebase/gh-ost that referenced this pull request Jan 2, 2024
* Cleanup whitespace in SQL query text

* cleanup

* Add indent

* Update unit tests

* Update unit tests, pt 2

* Fix tweaks

* Fix merge conflict resolution

Signed-off-by: Tim Vaillancourt <[email protected]>

---------

Signed-off-by: Tim Vaillancourt <[email protected]>
d-bytebase pushed a commit to bytebase/gh-ost that referenced this pull request Jan 2, 2024
* Add `focal` build

* upgrade codeQL action to v2

* Pin docker image to stretch (github#1324)

* pin stretch image

* update stretch repo

* Update Dockerfile.test

* parse binlog timestamp in UTC (github#1322)

* upgrade standard library deps (github#1332)

* fix: typo (github#1331)

Co-authored-by: Tim Vaillancourt <[email protected]>

* Remove stale RELEASE_VERSION file (github#1349)

Signed-off-by: Tim Vaillancourt <[email protected]>

* Force index in unique key range queries (github#1237)

* WIP

* Pass entire sql.UniqueKey

* newline for limit

* Rename var

---------

Co-authored-by: meiji163 <[email protected]>

* Include git commit in version (github#1347)

* Include git commit in version

Signed-off-by: Tim Vaillancourt <[email protected]>

* Make --version output change less-breaking

---------

Signed-off-by: Tim Vaillancourt <[email protected]>

* Fix tokens in inspector logging (github#1226)

* Cleanup whitespace and comments in SQL query text (github#1246)

* Cleanup whitespace in SQL query text

* cleanup

* Add indent

* Update unit tests

* Update unit tests, pt 2

* Fix tweaks

* Fix merge conflict resolution

Signed-off-by: Tim Vaillancourt <[email protected]>

---------

Signed-off-by: Tim Vaillancourt <[email protected]>

* Fix `--version` output (github#1352)

* Fix `--version` output

Signed-off-by: Tim Vaillancourt <[email protected]>

* Always fallback version/commit if undef

Signed-off-by: Tim Vaillancourt <[email protected]>

---------

Signed-off-by: Tim Vaillancourt <[email protected]>

* Update to `go1.21` (github#1351)

* go1.21 + bullseye

Signed-off-by: Tim Vaillancourt <[email protected]>

* go1.21 + bullseye pt 2

Signed-off-by: Tim Vaillancourt <[email protected]>

* checkout before setup-go

Signed-off-by: Tim Vaillancourt <[email protected]>

* go fmt

Signed-off-by: Tim Vaillancourt <[email protected]>

* Use golangci-lint 1.54.2 to support go1.21

Signed-off-by: Tim Vaillancourt <[email protected]>

* stop using io/ioutil to make linter happy

Signed-off-by: Tim Vaillancourt <[email protected]>

* Fix typo

Signed-off-by: Tim Vaillancourt <[email protected]>

* Lint

Signed-off-by: Tim Vaillancourt <[email protected]>

* revert replica-tests CI to ubuntu 20 due to linker errors

Signed-off-by: Tim Vaillancourt <[email protected]>

* Update ensure-go-installed

* use `ubuntu-latest` for `ci` job

Signed-off-by: Tim Vaillancourt <[email protected]>

* stretch -> bullseye

Signed-off-by: Tim Vaillancourt <[email protected]>

---------

Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>

* Replace deprecated `github.com/satori/go.uuid` lib (github#1354)

Signed-off-by: Tim Vaillancourt <[email protected]>

* Add `CODEOWNERS` file to auto-request reviews (github#1350)

Signed-off-by: Tim Vaillancourt <[email protected]>

* go mod tidy

* update test

* fix lint

---------

Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Tim Vaillancourt <[email protected]>
Co-authored-by: Rashiq <[email protected]>
Co-authored-by: meiji163 <[email protected]>
Co-authored-by: guangwu <[email protected]>
Co-authored-by: Tim Vaillancourt <[email protected]>
@@ -1150,7 +1151,7 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
return err
}

sessionQuery := "SET SESSION time_zone = '+00:00'"
sessionQuery := "SET /* gh-ost */ SESSION time_zone = '+00:00'"
Copy link
Contributor

@shaohk shaohk Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timvaillancourt Does the time zone set here need to be configured as this.migrationContext.ApplierTimeZone? I noticed that other sessions are using this.migrationContext.ApplierTimeZone for setting the time zone, but here it is set to +00:00. Should this be adjusted?

Copy link
Collaborator Author

@timvaillancourt timvaillancourt Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaohk good question, that sounds more correct than +00:00 🤔

Based on the soak testing this logic has seen I don't think this causes an integrity problem, however. I think that may be because binlog row events contain the values from that primary/master (including dates/times), so it probably doesn't matter what timezone the applier session uses here. I believe gh-ost is using the decoded binlog row event values only

Fewer "what if?" questions is a good thing though, so I would still welcome this change if it passes integration testing at GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants