@JsonValue @Override public String toString() { return LocalDate.ofEpochDay(days).toString(); } }
public static Optional<LocalDate> fromMetastoreDate(Date date) { if (date == null) { return Optional.empty(); } return Optional.of(LocalDate.ofEpochDay(date.getDaysSinceEpoch())); }
private static ArrayValue readDateArray( ByteBuffer bb, int offset ) { final int len = bb.getInt( offset ); offset += Integer.BYTES; final LocalDate[] array = new LocalDate[len]; for ( int i = 0; i < len; i++ ) { array[i] = LocalDate.ofEpochDay( bb.getLong( offset ) ); offset += Long.BYTES; } return dateArray( array ); }
@Override public Object read( ReadableClosableChannel from ) throws IOException { return LocalDate.ofEpochDay( from.getLong() ); }
public static LocalDate epochDateRaw( long epochDay ) { return assertValidArgument( () -> LocalDate.ofEpochDay( epochDay ) ); }
private static Date intToDate(Integer input) { if (input == null) { return null; } return Date.valueOf(LocalDate.ofEpochDay(input)); }
@JsonValue @Override public String toString() { return LocalDate.ofEpochDay(days).toString(); } }
private static Expression toStringLiteral(Type type, double value) { if (type.equals(BigintType.BIGINT) || type.equals(IntegerType.INTEGER) || type.equals(SmallintType.SMALLINT) || type.equals(TinyintType.TINYINT)) { return new StringLiteral(Long.toString(round(value))); } if (type.equals(DoubleType.DOUBLE) || type instanceof DecimalType) { return new StringLiteral(Double.toString(value)); } if (type.equals(RealType.REAL)) { return new StringLiteral(Float.toString((float) value)); } if (type.equals(DATE)) { return new StringLiteral(LocalDate.ofEpochDay(round(value)).toString()); } throw new IllegalArgumentException("Unexpected type: " + type); } }
private static Optional<LocalDate> getDateValue(ConnectorSession session, Type type, Block block) { return block.isNull(0) ? Optional.empty() : Optional.of(LocalDate.ofEpochDay(((SqlDate) type.getObjectValue(session, block, 0)).getDays())); }
private static ArrayValue dateArray( int... epochDays ) { LocalDate[] localDates = new LocalDate[epochDays.length]; for ( int i = 0; i < epochDays.length; i++ ) { localDates[i] = ofEpochDay( epochDays[i] ); } return Values.dateArray( localDates ); }
private LocalDate nextDateRaw() { return ofEpochDay( longBetween( LocalDate.MIN.toEpochDay(), LocalDate.MAX.toEpochDay() ) ); }
public static SqlTime sqlTimeOf(LocalTime time, Session session) { if (session.toConnectorSession().isLegacyTimestamp()) { long millisUtc = LocalDate.ofEpochDay(0) .atTime(time) .atZone(UTC) .withZoneSameLocal(ZoneId.of(session.getTimeZoneKey().getId())) .toInstant() .toEpochMilli(); return new SqlTime(millisUtc, session.getTimeZoneKey()); } return new SqlTime(NANOSECONDS.toMillis(time.toNanoOfDay())); }
private static long millisUtc(OffsetTime offsetTime) { return offsetTime.atDate(LocalDate.ofEpochDay(0)).toInstant().toEpochMilli(); }
@Test public void testDuplicatesInIndexSeekByTemporal() throws Exception { testDuplicatesInIndexSeek( ofEpochDay( 303 ) ); }
@Test public void testMergeDateColumnStatistics() { assertMergeHiveColumnStatistics( HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.empty(), Optional.empty())).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.empty(), Optional.empty())).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.empty(), Optional.empty())).build()); assertMergeHiveColumnStatistics( HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.of(LocalDate.ofEpochDay(1)), Optional.of(LocalDate.ofEpochDay(2)))).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.empty(), Optional.empty())).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.of(LocalDate.ofEpochDay(1)), Optional.of(LocalDate.ofEpochDay(2)))).build()); assertMergeHiveColumnStatistics( HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.of(LocalDate.ofEpochDay(1)), Optional.of(LocalDate.ofEpochDay(2)))).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.of(LocalDate.ofEpochDay(0)), Optional.of(LocalDate.ofEpochDay(3)))).build(), HiveColumnStatistics.builder().setDateStatistics(new DateStatistics(Optional.of(LocalDate.ofEpochDay(0)), Optional.of(LocalDate.ofEpochDay(3)))).build()); }
@Test public void testDateStatsToColumnStatistics() { DateColumnStatsData dateColumnStatsData = new DateColumnStatsData(); dateColumnStatsData.setLowValue(new Date(1000)); dateColumnStatsData.setHighValue(new Date(2000)); dateColumnStatsData.setNumNulls(1); dateColumnStatsData.setNumDVs(20); ColumnStatisticsObj columnStatisticsObj = new ColumnStatisticsObj("my_col", DATE_TYPE_NAME, dateStats(dateColumnStatsData)); HiveColumnStatistics actual = fromMetastoreApiColumnStatistics(columnStatisticsObj, OptionalLong.of(1000)); assertEquals(actual.getIntegerStatistics(), Optional.empty()); assertEquals(actual.getDoubleStatistics(), Optional.empty()); assertEquals(actual.getDecimalStatistics(), Optional.empty()); assertEquals(actual.getDateStatistics(), Optional.of(new DateStatistics(Optional.of(LocalDate.ofEpochDay(1000)), Optional.of(LocalDate.ofEpochDay(2000))))); assertEquals(actual.getBooleanStatistics(), Optional.empty()); assertEquals(actual.getMaxValueSizeInBytes(), OptionalLong.empty()); assertEquals(actual.getTotalSizeInBytes(), OptionalLong.empty()); assertEquals(actual.getNullsCount(), OptionalLong.of(1)); assertEquals(actual.getDistinctValuesCount(), OptionalLong.of(19)); }
@Test public void shouldDeserializeTimestampToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.timestampMillis().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MILLIS.between( LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeTimestampToInteger() { shouldDeserializeTypeCorrectly( LogicalTypes.timestampMicros().addToSchema( org.apache.avro.SchemaBuilder.builder().longType()), ChronoUnit.MICROS.between( LocalDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT), LocalDateTime.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeDateToBigint() { shouldDeserializeTypeCorrectly( LogicalTypes.date().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()), Schema.OPTIONAL_INT64_SCHEMA ); }
@Test public void shouldDeserializeDateToInteger() { shouldDeserializeTypeCorrectly( LogicalTypes.date().addToSchema( org.apache.avro.SchemaBuilder.builder().intType()), (int) ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now()), Schema.OPTIONAL_INT32_SCHEMA ); }