-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add support for precision for TIMESTAMP in Postgresql type mapping #5124
Conversation
Please add type mapping docs for postgresql as part of this PR so it is clear to users. |
return createPostgreSqlQueryRunner(server, extraProperties, connectorProperties, tables, 3); | ||
} | ||
|
||
public static DistributedQueryRunner createPostgreSqlQueryRunner( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather drop this commit.
The added burden of an overload is not justified for arguably small benefit this brings.
@@ -1199,15 +1200,6 @@ public void testArrayTimestampWithTimeZone(boolean insertWithPresto) | |||
tests.execute(getQueryRunner(), sessionWithArrayAsArray(), dataSetup); | |||
} | |||
|
|||
@DataProvider | |||
public Object[][] testTimestampWithTimeZoneDataProvider() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cmt title is
Rename misleading testTimestampWithTimeZoneDataProvider
it's removal not "rename"
"misleading" is misleading. It was very nicely called "DataProvider", i do not find anything misleading in that and next time would call it the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "Use generic trueFalse data provider for timestamp tests"
long precision = timestampType.getPrecision(); | ||
checkArgument(precision <= MAX_SHORT_PRECISION, "Precision is out of range: %s", precision); | ||
Instant instant = localDateTime.atZone(UTC).toInstant(); | ||
return instant.getEpochSecond() * MICROSECONDS_PER_SECOND + roundDiv(instant.getNano(), NANOSECONDS_PER_MICROSECOND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if timestampType.precision < 6, you need to round/truncate here
@martint what is the correct way to do this?
there are some utility methods in io.prestosql.spi.type.Timestamps
, but I do not see something that's immediately applicable.
{ | ||
return Instant.ofEpochMilli(floorDiv(value, MICROSECONDS_PER_MILLISECOND)).atZone(UTC).toLocalDateTime(); | ||
int precision = timestampType.getPrecision(); | ||
checkArgument(precision <= MAX_SHORT_PRECISION && precision >= 0, "Precision is out of range: %s", precision); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not really need to validate this here. If someone provided epochMicros
, it;'s all you need.
long epochSecond = floorDiv(epochMicros, MICROSECONDS_PER_SECOND); | ||
int nanoFraction = floorMod(epochMicros, MICROSECONDS_PER_SECOND) * NANOSECONDS_PER_MICROSECOND; | ||
Instant instant = Instant.ofEpochSecond(epochSecond, nanoFraction); | ||
return LocalDateTime.ofInstant(instant, UTC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could unify & reuse with io.prestosql.spi.type.Timestamps#formatTimestamp(int precision, long epochMicros, int picosOfMicro)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but I am not sure if we could extend spi with random methods. We should keep it fairly stable. Also the spi methods cares about picosOfMicro
which we do not care about here. With picosOfMicro
you cannot create a method which just returns LocalDateTime
, which we need here. And have a specific method version which does not take picosOfSeconds
and returns LocalDateTime
seems to specific to me, to be put in spi.
@@ -262,7 +262,7 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) | |||
} | |||
if (TIMESTAMP_MILLIS.equals(type)) { | |||
// TODO use `timestampWriteFunction` | |||
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp()); | |||
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP)); | |
return WriteMapping.longMapping("datetime", timestampWriteFunctionUsingSqlTimestamp(TIMESTAMP_MILLIS)); |
.addRoundTrip(timestampDataType(), timeGapInKathmandu); | ||
DataTypeTest tests = DataTypeTest.create(true); | ||
for (int precision : List.of(3, 6)) { | ||
// test all standard cases with precision 3 and 6 to make sure the long and short TIMESTAMP WITH TIME ZONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"TIMESTAMP WITH TIME ZONE"
also, is 3 and 6 actually different cases?
i think in timestamp case, we go with the same code path
(ok to leave the test coverage, but if true, change the commnt)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - you noticed it too - yeah - it same case. I dropped the coverage.
} | ||
} | ||
|
||
private DataType<List<LocalDateTime>> arrayOfTimestampDataType(int precision, boolean insertWithPresto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this belong to Simplify flow in timestamp with timezone mapping tests
commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. This is specific to TIMESTAMP
not TIMESTAMP w/TZ
. So it belongs to last commit.
This is a point change regarding one specific type and adding general type mapping documentation is substantial effort itself. |
Add support for mapping TIMESTAMP from Presto to PostgreSQL (and vice versa) for precisions 1 to 6. It covers all precisions currently supported by PostgreSQL.
} | ||
} | ||
|
||
private DataType<List<LocalDateTime>> arrayOfTimestampDataType(int precision, boolean insertWithPresto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. This is specific to TIMESTAMP
not TIMESTAMP w/TZ
. So it belongs to last commit.
dataType = arrayDataType(timestampDataType(), "timestamp[]"); | ||
dataSetup = postgresCreateAndInsert("tpch.test_array_timestamp"); | ||
DataTypeTest tests = DataTypeTest.create(true); | ||
for (int precision : List.of(3, 6)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will drop this for. As representation is same for 3 and 6 for TIMESTAMP
.addRoundTrip(timestampDataType(), timeGapInKathmandu); | ||
DataTypeTest tests = DataTypeTest.create(true); | ||
for (int precision : List.of(3, 6)) { | ||
// test all standard cases with precision 3 and 6 to make sure the long and short TIMESTAMP WITH TIME ZONE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - you noticed it too - yeah - it same case. I dropped the coverage.
305f378
to
e7fdfe3
Compare
Replaces #4570