本文整理汇总了Java中org.apache.calcite.avatica.util.DateTimeUtils类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeUtils类的具体用法?Java DateTimeUtils怎么用?Java DateTimeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeUtils类属于org.apache.calcite.avatica.util包,在下文中一共展示了DateTimeUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static JdbcResultSet create(String connectionId, int statementId,
ResultSet resultSet, int maxRowCount, Meta.Signature signature) {
try {
final Calendar calendar = DateTimeUtils.calendar();
final int fetchRowCount;
if (maxRowCount == JdbcMeta.UNLIMITED_COUNT) {
fetchRowCount = -1;
} else if (maxRowCount < 0L) {
fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
} else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) {
fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
} else {
fetchRowCount = maxRowCount;
}
final Meta.Frame firstFrame = frame(null, resultSet, 0, fetchRowCount, calendar,
Optional.of(signature));
if (firstFrame.done) {
resultSet.close();
}
return new JdbcResultSet(connectionId, statementId, true, signature,
firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:26,代码来源:JdbcResultSet.java
示例2: testBase64
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
@Test public void testBase64() {
byte[] bytes = "qwertyasdf".getBytes(UTF_8);
// Plain bytes get put into protobuf for simplicitly
Common.TypedValue proto = Common.TypedValue.newBuilder().setBytesValue(
com.google.protobuf.ByteString.copyFrom(bytes))
.setType(Common.Rep.BYTE_STRING).build();
// But we should get back a b64-string to make sure TypedValue doesn't get confused.
Object deserializedObj = TypedValue.getSerialFromProto(proto);
assertThat(deserializedObj, is(instanceOf(String.class)));
assertEquals(new ByteString(bytes).toBase64String(), (String) deserializedObj);
// But we should get a non-b64 byte array as the JDBC representation
deserializedObj =
TypedValue.protoToJdbc(proto, DateTimeUtils.calendar());
assertThat(deserializedObj, is(instanceOf(byte[].class)));
assertArrayEquals(bytes, (byte[]) deserializedObj);
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:19,代码来源:TypedValueTest.java
示例3: create
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static QuarkMetaResultSet create(String connectionId, int statementId,
ResultSet resultSet,
long maxRowCount, Meta.Signature signature) {
try {
final Calendar calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
final int fetchRowCount;
if (maxRowCount == QuarkMetaImpl.UNLIMITED_COUNT) {
fetchRowCount = -1;
} else if (maxRowCount < 0L) {
fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
} else if (maxRowCount > AvaticaStatement.DEFAULT_FETCH_SIZE) {
fetchRowCount = AvaticaStatement.DEFAULT_FETCH_SIZE;
} else {
fetchRowCount = (int) maxRowCount;
}
final Meta.Frame firstFrame = frame(resultSet, 0, fetchRowCount, calendar);
if (firstFrame.done) {
resultSet.close();
}
return new QuarkMetaResultSet(connectionId, statementId, true, signature,
firstFrame);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
开发者ID:qubole,项目名称:quark,代码行数:26,代码来源:QuarkMetaResultSet.java
示例4: convert
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
private static Object convert(Object o, Class clazz) {
if (o == null) {
return null;
}
Primitive primitive = Primitive.of(clazz);
if (primitive != null) {
clazz = primitive.boxClass;
} else {
primitive = Primitive.ofBox(clazz);
}
if (clazz.isInstance(o)) {
return o;
}
if (o instanceof Date && primitive != null) {
o = ((Date) o).getTime() / DateTimeUtils.MILLIS_PER_DAY;
}
if (o instanceof Number && primitive != null) {
return primitive.number((Number) o);
}
return o;
}
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:Elasticsearch2Enumerator.java
示例5: dateTimeLiteral
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
private RexLiteral dateTimeLiteral(RexBuilder rexBuilder, Calendar calendar,
RexNode operand) {
final TimestampString ts;
final int p;
switch (operand.getType().getSqlTypeName()) {
case TIMESTAMP:
ts = TimestampString.fromCalendarFields(calendar);
p = operand.getType().getPrecision();
return rexBuilder.makeTimestampLiteral(ts, p);
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
ts = TimestampString.fromCalendarFields(calendar);
final TimeZone tz = TimeZone.getTimeZone(this.timeZone);
final TimestampString localTs =
new TimestampWithTimeZoneString(ts, tz)
.withTimeZone(DateTimeUtils.UTC_ZONE)
.getLocalTimestampString();
p = operand.getType().getPrecision();
return rexBuilder.makeTimestampWithLocalTimeZoneLiteral(localTs, p);
case DATE:
final DateString d = DateString.fromCalendarFields(calendar);
return rexBuilder.makeDateLiteral(d);
default:
throw Util.unexpected(operand.getType().getSqlTypeName());
}
}
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:DateRangeRules.java
示例6: subtractMonths
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static int subtractMonths(long t0, long t1) {
final long millis0 =
DateTimeUtils.floorMod(t0, DateTimeUtils.MILLIS_PER_DAY);
final int d0 = (int) DateTimeUtils.floorDiv(t0 - millis0,
DateTimeUtils.MILLIS_PER_DAY);
final long millis1 =
DateTimeUtils.floorMod(t1, DateTimeUtils.MILLIS_PER_DAY);
final int d1 = (int) DateTimeUtils.floorDiv(t1 - millis1,
DateTimeUtils.MILLIS_PER_DAY);
int x = subtractMonths(d0, d1);
final long d2 = addMonths(d1, x);
if (d2 == d0 && millis0 < millis1) {
--x;
}
return x;
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:SqlFunctions.java
示例7: parseTimestampLiteral
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static SqlTimestampLiteral parseTimestampLiteral(String s,
SqlParserPos pos) {
final String dateStr = parseString(s);
final DateTimeUtils.PrecisionTime pt =
DateTimeUtils.parsePrecisionDateTimeLiteral(dateStr,
Format.PER_THREAD.get().timestamp, DateTimeUtils.UTC_ZONE, -1);
if (pt == null) {
throw SqlUtil.newContextException(pos,
RESOURCE.illegalLiteral("TIMESTAMP", s,
RESOURCE.badFormat(DateTimeUtils.TIMESTAMP_FORMAT_STRING).str()));
}
final TimestampString ts =
TimestampString.fromCalendarFields(pt.getCalendar())
.withFraction(pt.getFraction());
return SqlLiteral.createTimestamp(ts, pt.getPrecision(), pos);
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:SqlParserUtil.java
示例8: getMillisSinceEpoch
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
/** Returns the number of milliseconds since the epoch. */
public long getMillisSinceEpoch() {
final int year = Integer.valueOf(v.substring(0, 4));
final int month = Integer.valueOf(v.substring(5, 7));
final int day = Integer.valueOf(v.substring(8, 10));
final int h = Integer.valueOf(v.substring(11, 13));
final int m = Integer.valueOf(v.substring(14, 16));
final int s = Integer.valueOf(v.substring(17, 19));
final int ms = getMillisInSecond();
final int d = DateTimeUtils.ymdToUnixDate(year, month, day);
return d * DateTimeUtils.MILLIS_PER_DAY
+ h * DateTimeUtils.MILLIS_PER_HOUR
+ m * DateTimeUtils.MILLIS_PER_MINUTE
+ s * DateTimeUtils.MILLIS_PER_SECOND
+ ms;
}
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:TimestampString.java
示例9: generateCert
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
private X509CertificateObject generateCert(String keyName, KeyPair kp, boolean isCertAuthority,
PublicKey signerPublicKey, PrivateKey signerPrivateKey) throws IOException,
CertIOException, OperatorCreationException, CertificateException,
NoSuchAlgorithmException {
Calendar startDate = DateTimeUtils.calendar();
Calendar endDate = DateTimeUtils.calendar();
endDate.add(Calendar.YEAR, 100);
BigInteger serialNumber = BigInteger.valueOf(startDate.getTimeInMillis());
X500Name issuer = new X500Name(
IETFUtils.rDNsFromString("cn=localhost", RFC4519Style.INSTANCE));
JcaX509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(issuer,
serialNumber, startDate.getTime(), endDate.getTime(), issuer, kp.getPublic());
JcaX509ExtensionUtils extensionUtils = new JcaX509ExtensionUtils();
certGen.addExtension(Extension.subjectKeyIdentifier, false,
extensionUtils.createSubjectKeyIdentifier(kp.getPublic()));
certGen.addExtension(Extension.basicConstraints, false,
new BasicConstraints(isCertAuthority));
certGen.addExtension(Extension.authorityKeyIdentifier, false,
extensionUtils.createAuthorityKeyIdentifier(signerPublicKey));
if (isCertAuthority) {
certGen.addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.keyCertSign));
}
X509CertificateHolder cert = certGen.build(
new JcaContentSignerBuilder(SIGNING_ALGORITHM).build(signerPrivateKey));
return new X509CertificateObject(cert.toASN1Structure());
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:28,代码来源:SslDriverTest.java
示例10: testLegacyDecimalParsing
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
@Test public void testLegacyDecimalParsing() {
final BigDecimal decimal = new BigDecimal("123451234512345");
final Calendar calendar = DateTimeUtils.calendar();
// CALCITE-1103 Decimals were (incorrectly) getting serialized as normal "numbers" which
// caused them to use the numberValue field. TypedValue should still be able to handle
// values like this (but large values will be truncated and return bad values).
Common.TypedValue oldProtoStyle = Common.TypedValue.newBuilder().setType(Common.Rep.NUMBER)
.setNumberValue(decimal.longValue()).build();
TypedValue fromProtoTv = TypedValue.fromProto(oldProtoStyle);
Object o = fromProtoTv.toJdbc(calendar);
assertEquals(decimal, o);
}
开发者ID:apache,项目名称:calcite-avatica,代码行数:15,代码来源:TypedValueTest.java
示例11: evaluate
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
@Override public BeamSqlPrimitive evaluate(BeamRecord inputRow, BoundedWindow window) {
Long time = opValueEvaluated(1, inputRow, window);
TimeUnitRange unit = ((BeamSqlPrimitive<TimeUnitRange>) op(0)).getValue();
switch (unit) {
case YEAR:
case MONTH:
case DAY:
Long timeByDay = time / 1000 / 3600 / 24;
Long extracted = DateTimeUtils.unixDateExtract(
unit,
timeByDay
);
return BeamSqlPrimitive.of(outputType, extracted);
case DOY:
case DOW:
case WEEK:
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(time));
return BeamSqlPrimitive.of(outputType, (long) calendar.get(typeMapping.get(unit)));
case QUARTER:
calendar = Calendar.getInstance();
calendar.setTime(new Date(time));
long ret = calendar.get(Calendar.MONTH) / 3;
if (ret * 3 < calendar.get(Calendar.MONTH)) {
ret += 1;
}
return BeamSqlPrimitive.of(outputType, ret);
default:
throw new UnsupportedOperationException(
"Extract for time unit: " + unit + " not supported!");
}
}
开发者ID:apache,项目名称:beam,代码行数:38,代码来源:BeamSqlExtractExpression.java
示例12: evaluate
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
@Override public BeamSqlPrimitive evaluate(BeamRecord inputRow, BoundedWindow window) {
Date date = opValueEvaluated(0, inputRow, window);
long time = date.getTime();
TimeUnitRange unit = ((BeamSqlPrimitive<TimeUnitRange>) op(1)).getValue();
long newTime = DateTimeUtils.unixTimestampFloor(unit, time);
Date newDate = new Date(newTime);
return BeamSqlPrimitive.of(outputType, newDate);
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:BeamSqlDateFloorExpression.java
示例13: evaluate
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
@Override public BeamSqlPrimitive evaluate(BeamRecord inputRow, BoundedWindow window) {
Date date = opValueEvaluated(0, inputRow, window);
long time = date.getTime();
TimeUnitRange unit = ((BeamSqlPrimitive<TimeUnitRange>) op(1)).getValue();
long newTime = DateTimeUtils.unixTimestampCeil(unit, time);
Date newDate = new Date(newTime);
return BeamSqlPrimitive.of(outputType, newDate);
}
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:BeamSqlDateCeilExpression.java
示例14: shift
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
private static Time shift(Time v) {
if (v == null) {
return null;
}
long time = v.getTime();
int offset = TimeZone.getDefault().getOffset(time);
return new Time((time + offset) % DateTimeUtils.MILLIS_PER_DAY);
}
开发者ID:bitnine-oss,项目名称:octopus,代码行数:9,代码来源:JdbcUtils.java
示例15: shift
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
private static Time shift(Time v) {
if (v == null) {
return null;
}
long time = v.getTime();
int offset = TimeZone.getDefault().getOffset(time);
return new Time((time + offset) % DateTimeUtils.MILLIS_PER_DAY);
}
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:JdbcUtils.java
示例16: normalize
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
/** Normalizes a TIME value into 00:00:00..23:59:39. */
private Expression normalize(SqlTypeName typeName, Expression e) {
switch (typeName) {
case TIME:
return Expressions.call(BuiltInMethod.FLOOR_MOD.method, e,
Expressions.constant(DateTimeUtils.MILLIS_PER_DAY));
default:
return e;
}
}
开发者ID:apache,项目名称:calcite,代码行数:11,代码来源:RexImpTable.java
示例17: convertCall
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
// TIMESTAMPDIFF(unit, t1, t2)
// => (t2 - t1) UNIT
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlLiteral unitLiteral = call.operand(0);
TimeUnit unit = unitLiteral.symbolValue(TimeUnit.class);
BigDecimal multiplier = BigDecimal.ONE;
BigDecimal divider = BigDecimal.ONE;
switch (unit) {
case MICROSECOND:
case MILLISECOND:
case WEEK:
multiplier = BigDecimal.valueOf(DateTimeUtils.MILLIS_PER_SECOND);
divider = unit.multiplier;
unit = TimeUnit.SECOND;
break;
case QUARTER:
divider = unit.multiplier;
unit = TimeUnit.MONTH;
break;
}
final SqlIntervalQualifier qualifier =
new SqlIntervalQualifier(unit, null, SqlParserPos.ZERO);
final RexNode op2 = cx.convertExpression(call.operand(2));
final RexNode op1 = cx.convertExpression(call.operand(1));
final RelDataType intervalType =
cx.getTypeFactory().createTypeWithNullability(
cx.getTypeFactory().createSqlIntervalType(qualifier),
op1.getType().isNullable() || op2.getType().isNullable());
final RexCall rexCall = (RexCall) rexBuilder.makeCall(
intervalType, SqlStdOperatorTable.MINUS_DATE,
ImmutableList.of(op2, op1));
final RelDataType intType =
cx.getTypeFactory().createTypeWithNullability(
cx.getTypeFactory().createSqlType(SqlTypeName.INTEGER),
SqlTypeUtil.containsNullable(rexCall.getType()));
RexNode e = rexBuilder.makeCast(intType, rexCall);
return rexBuilder.multiplyDivide(e, multiplier, divider);
}
开发者ID:apache,项目名称:calcite,代码行数:40,代码来源:StandardConvertletTable.java
示例18: timeWithLocalTimeZoneToTimestamp
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static long timeWithLocalTimeZoneToTimestamp(String date, int v, TimeZone timeZone) {
final TimeWithTimeZoneString tTZ = TimeWithTimeZoneString.fromMillisOfDay(v)
.withTimeZone(DateTimeUtils.UTC_ZONE);
return new TimestampWithTimeZoneString(date + " " + tTZ.toString())
.withTimeZone(timeZone)
.getLocalTimestampString()
.getMillisSinceEpoch();
}
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:SqlFunctions.java
示例19: timeWithLocalTimeZoneToTimestampWithLocalTimeZone
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
public static long timeWithLocalTimeZoneToTimestampWithLocalTimeZone(String date, int v) {
final TimeWithTimeZoneString tTZ = TimeWithTimeZoneString.fromMillisOfDay(v)
.withTimeZone(DateTimeUtils.UTC_ZONE);
return new TimestampWithTimeZoneString(date + " " + tTZ.toString())
.getLocalTimestampString()
.getMillisSinceEpoch();
}
开发者ID:apache,项目名称:calcite,代码行数:8,代码来源:SqlFunctions.java
示例20: currentTime
import org.apache.calcite.avatica.util.DateTimeUtils; //导入依赖的package包/类
/** SQL {@code CURRENT_TIME} function. */
@NonDeterministic
public static int currentTime(DataContext root) {
int time = (int) (currentTimestamp(root) % DateTimeUtils.MILLIS_PER_DAY);
if (time < 0) {
time += DateTimeUtils.MILLIS_PER_DAY;
}
return time;
}
开发者ID:apache,项目名称:calcite,代码行数:10,代码来源:SqlFunctions.java
注:本文中的org.apache.calcite.avatica.util.DateTimeUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论