提交 2937be4a authored 作者: Thomas Mueller's avatar Thomas Mueller

Pull request #125: Improved Oracle compatibility with truncate with timestamps and dates.

上级 d3853404
......@@ -2975,11 +2975,13 @@ CALL HASH('SHA256', STRINGTOUTF8('Password'), 1000)
"
"Functions (Numeric)","TRUNCATE","
{ TRUNC | TRUNCATE } ( { {numeric, digitsInt} | timestamp } )
{ TRUNC | TRUNCATE } ( { {numeric, digitsInt} | timestamp | date | timestampString } )
","
Truncates to a number of digits (to the next value closer to 0).
This method returns a double.
When used with a timestamp, truncates a timestamp to a date (day) value.
When used with a date, truncates a date to a date (day) value less time part.
When used with a timestamp as string, truncates a timestamp to a date (day) value.
","
TRUNCATE(VALUE, 2)
"
......
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Pull request #125: Improved Oracle compatibility with "truncate" with timestamps and dates.
</li>
<li>Pull request #127: Linked tables now support geometry columns.
</li>
<li>ABS(CAST(0.0 AS DOUBLE)) returned -0.0 instead of 0.0.
......
......@@ -1224,6 +1224,24 @@ public class Function extends Expression implements FunctionCall {
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
result = ValueTimestamp.fromMillis(c.getTimeInMillis());
} else if (v0.getType() == Value.DATE) {
ValueDate vd = (ValueDate) v0;
Calendar c = Calendar.getInstance();
c.setTime(vd.getDate());
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
result = ValueTimestamp.fromMillis(c.getTimeInMillis());
} else if (v0.getType() == Value.STRING) {
ValueString vd = (ValueString) v0;
Calendar c = Calendar.getInstance();
c.setTime(ValueTimestamp.parse(vd.getString()).getDate());
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
result = ValueTimestamp.fromMillis(c.getTimeInMillis());
} else {
double d = v0.getDouble();
int p = v1 == null ? 0 : v1.getInt();
......
select trunc('2015-05-29 15:00:00');
> 2015-05-29 00:00:00.0;
select trunc('2015-05-29');
> 2015-05-29 00:00:00.0;
select trunc(timestamp '2000-01-01 10:20:30.0');
> 2000-01-01 00:00:00.0;
select 1000L / 10;
> 100;
select * from (select x as y from dual order by y);
......
......@@ -100,7 +100,9 @@ public class TestBitStream extends TestBase {
}
};
o.writeGolomb(div, value);
int size = Out.getGolombSize(div, value);
String got = buff.toString();
assertEquals(size, got.length());
assertEquals(expected, got);
}
......
......@@ -126,6 +126,23 @@ public class BitStream {
}
}
/**
* Get the size of the Golomb code for this value.
*
* @param divisor the divisor
* @param value the value
* @return the number of bits
*/
public static int getGolombSize(int divisor, int value) {
int q = value / divisor;
int r = value - q * divisor;
int bit = 31 - Integer.numberOfLeadingZeros(divisor - 1);
if (r < ((2 << bit) - divisor)) {
bit--;
}
return bit + q + 2;
}
/**
* Write a bit.
*
......@@ -195,8 +212,10 @@ public class BitStream {
}
codes = new int[frequencies.length];
tree = queue.poll();
if (tree != null) {
tree.initCodes(codes, 1);
}
}
/**
* Write a value.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论