/** * Format a date to the Java source code that represents this object. * * @param x the date to convert * @return the Java source code */ protected static String quoteDate(java.sql.Date x) { if (x == null) { return "null"; } return "Date.valueOf(\"" + x.toString() + "\")"; }
@Override public String toString() { return "{d '" + value.toString() + "'}"; } }
/** * Format a date to the Java source code that represents this object. * * @param x the date to convert * @return the Java source code */ protected static String quoteDate(java.sql.Date x) { if (x == null) { return "null"; } return "Date.valueOf(\"" + x.toString() + "\")"; }
@Override public String vectorExpressionParameters() { return "col " + colNum + ", val " + value.toString(); }
public void setDate(int parameterIndex, Date x) throws SQLException { this.parameters.put(parameterIndex, "'" + x.toString() + "'"); }
public String objectToSQLString(Date value, Dialect dialect) throws Exception { final java.sql.Date jdbcDate = java.sql.Date.class.isInstance( value ) ? ( java.sql.Date ) value : new java.sql.Date( value.getTime() ); // TODO : use JDBC date literal escape syntax? -> {d 'date-string'} in yyyy-mm-dd format return StringType.INSTANCE.objectToSQLString( jdbcDate.toString(), dialect ); }
@Override public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeString(value.toString()); }
@Override public String toString() { // For toString, the time does not matter return get(false).toString(); }
@Override public String vectorExpressionParameters() { return getColumnParamString(0, colNum) + ", val " + value.toString(); }
@Override public void visit(DateValue dateValue) { buffer.append("{d '").append(dateValue.getValue().toString()).append("'}"); }
public void visit(DateValue dateValue) { buffer.append("{d '" + dateValue.getValue().toString() + "'}"); } public void visit(TimestampValue timestampValue) {
@Override public List<MutablePair<String, String>> getIntervals(String lowerBound, String upperBound, int numPartitions, TypeInfo typeInfo) { List<MutablePair<String, String>> intervals = new ArrayList<>(); Date dateLower = Date.valueOf(lowerBound); Date dateUpper = Date.valueOf(upperBound); double dateInterval = (dateUpper.getTime() - dateLower.getTime())/(double)numPartitions; Date splitDateLower, splitDateUpper; for (int i=0;i<numPartitions;i++) { splitDateLower = new Date(Math.round(dateLower.getTime() + dateInterval*i)); splitDateUpper = new Date(Math.round(dateLower.getTime() + dateInterval*(i+1))); if (splitDateLower.compareTo(splitDateUpper) < 0) { intervals.add(new MutablePair<String, String>(splitDateLower.toString(), splitDateUpper.toString())); } } return intervals; } }
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { if (parameterIndex < 1 || parameterIndex > args.length) { throw new SQLException("bad parameter index"); } if (x == null) { args[parameterIndex - 1] = nullrepl ? "" : null; } else { if (conn.useJulian) { args[parameterIndex - 1] = java.lang.Double.toString(SQLite.Database.julian_from_long(x.getTime())); } else { args[parameterIndex - 1] = x.toString(); } } blobs[parameterIndex - 1] = false; }
public void updateDate(int colIndex, java.sql.Date d) throws SQLException { isUpdatable(); if (tr == null || colIndex < 1 || colIndex > tr.ncolumns) { throw new SQLException("column " + colIndex + " not found"); } fillRowbuf(); rowbuf[colIndex - 1] = d.toString(); }
@Override public void serialize(java.sql.Date value, JsonGenerator g, SerializerProvider provider) throws IOException { if (_asTimestamp(provider)) { g.writeNumber(_timestamp(value)); return; } // Alas, can't just call `_serializeAsString()`.... if (_customFormat == null) { // 11-Oct-2016, tatu: For backwards-compatibility purposes, we shall just use // the awful standard JDK serialization via `sqlDate.toString()`... this // is problematic in multiple ways (including using arbitrary timezone...) g.writeString(value.toString()); return; } _serializeAsString(value, g, provider); } }
@Override protected void func(BytesColumnVector outV, long[] vector, int i) { dt.setTime(DateWritable.daysToMillis((int) vector[i])); byte[] temp = dt.toString().getBytes(); assign(outV, i, temp, temp.length); } }
@Override public void serialize(java.sql.Date value, JsonGenerator g, SerializerProvider provider) throws IOException { if (_asTimestamp(provider)) { g.writeNumber(_timestamp(value)); return; } // Alas, can't just call `_serializeAsString()`.... if (_customFormat == null) { // 11-Oct-2016, tatu: For backwards-compatibility purposes, we shall just use // the awful standard JDK serialization via `sqlDate.toString()`... this // is problematic in multiple ways (including using arbitrary timezone...) g.writeString(value.toString()); return; } _serializeAsString(value, g, provider); } }
@Test public void testDateAggFunction() throws Exception{ String query = "SELECT max(cast(HIRE_DATE as date)) as MAX_DATE, min(cast(HIRE_DATE as date)) as MIN_DATE" + " FROM `employee.json`"; String t = new Date(ISOChronology.getInstance().getDateTimeMillis(1998, 1, 1, 0)).toString(); String t1 = new Date(ISOChronology.getInstance().getDateTimeMillis(1993, 5, 1, 0)).toString(); String result = "MAX_DATE="+ t + "; " + "MIN_DATE=" + t1 + "\n"; withFull("cp") .sql(query) .returns(result); }
/** * @throws Exception If failed. */ @Test public void testSimpleObject() throws Exception { SimplePerson p = new SimplePerson(1, "Test", java.sql.Date.valueOf("1977-01-26"), 1000.55, 39, "CIO", 25); jcache().put("simplePersonKey", p); String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_GET, "key", "simplePersonKey"); info("Get command result: " + ret); JsonNode res = assertResponseSucceeded(ret, false); assertEquals(p.id, res.get("id").asInt()); assertEquals(p.name, res.get("name").asText()); assertEquals(p.birthday.toString(), res.get("birthday").asText()); assertEquals(p.salary, res.get("salary").asDouble()); assertNull(res.get("age")); assertEquals(p.post, res.get("post").asText()); assertEquals(25, res.get("bonus").asInt()); }
@Test public void testConvertToAvroStreamForDateTimeAsString() throws SQLException, IOException, ParseException { final JdbcCommon.AvroConversionOptions options = JdbcCommon.AvroConversionOptions .builder().convertNames(true).useLogicalTypes(false).build(); testConvertToAvroStreamForDateTime(options, (record, date) -> assertEquals(new Utf8(date.toString()), record.get("date")), (record, time) -> assertEquals(new Utf8(time.toString()), record.get("time")), (record, timestamp) -> assertEquals(new Utf8(timestamp.toString()), record.get("timestamp")) ); }