implydata/plyql

mysql-gateway timezone not working

exitNA opened this issue · 1 comments

i use:

plyql -h 127.0.0.1:8082 -Z "Asia/Shanghai" -i P2Y --experimental-mysql-gateway 3308
then, use mysql client connect to this server, query:
select max(__time) from test_table;
got result is:
+---------------------+
| max(__time) |
+---------------------+
| 2016-10-17 17:00:00 |
+---------------------+
but the real time shi 2016-10-18 01:00:00

when i use plyql directly, like:

plyql -h 172.22.16.8 --timezone "Asia/Shanghai" --force-number 'day' -q 'select max(__time) from test_table;'

i got the right result:
┌─────────────────────────────────────────┐
│ max(__time) │
├─────────────────────────────────────────┤
│ Tue Oct 18 2016 01:00:00 GMT+0800 (CST) │
└─────────────────────────────────────────┘

how can I solve this problem in mysql-gateway ?

Ok so I think I know what the confusion is.

$ plyql -h dm -q "SELECT TIME_FLOOR(TIMESTAMP '2016-09-11 12:34.56', 'P1D') as A" --output json
[
  {
    "A": {
      "type": "TIME",
      "value": "2016-09-11T00:00:00.000Z"
    }
  }
]
$ plyql -h dm -q "SELECT TIME_FLOOR(TIMESTAMP '2016-09-11 12:34.56', 'P1D') as A" --timezone America/Los_Angeles --output json
[
  {
    "A": {
      "type": "TIME",
      "value": "2016-09-11T07:00:00.000Z"
    }
  }
]
$ plyql -h dm -q "SELECT TIME_FLOOR(TIMESTAMP '2016-09-11 12:34.56', 'P1D') as A" --timezone Asia/Shanghai --output json
[
  {
    "A": {
      "type": "TIME",
      "value": "2016-09-10T16:00:00.000Z"
    }
  }
]
$ plyql -h dm -q "SELECT TIME_FLOOR(TIMESTAMP '2016-09-11 12:34.56', 'P1D', 'Asia/Shanghai') as A" --output json
[
  {
    "A": {
      "type": "TIME",
      "value": "2016-09-10T16:00:00.000Z"
    }
  }
]

the --timezone parameter is simply there to control the default timezone argument to the time manipulating functions TIME_FLOOR, TIME_BUCKET, TIME_SHIFT, etc

It is (as intended) there to control the timezone of the time manipulation NOT of the time display.
As such select max(__time) from test_table; is not in anyway way affected by the --timezone parameter as it stands. Since it does not use any of the time manipulator functions.

output mode json and mysql gateway always output time in UTC. output mode table (the default) out puts the time in your local timezone regardless of --timezone also (because reasons).

Anyhow @gianm has convinced me that this behavior should be changed to have --timezone affect the display also.

Hence: #69