private String getPostgresqlType(JsonNode clazz) { if (clazz.isTextual()) { try { DateTimeUtils.parseDate(clazz.asText()); return "date"; } catch (Exception e) { } try { DateTimeUtils.parseTimestamp(clazz.asText()); return "timestamp"; } catch (Exception e) { } return "text"; } else if (clazz.isFloat() || clazz.isDouble()) { return "float8"; } else if (clazz.isNumber()) { return "int8"; } else if (clazz.isBoolean()) { return "bool"; } else if (clazz.isArray()) { if(clazz.get(0).isObject()){ return "jsonb"; } return getPostgresqlType(clazz.get(0)) + "[]"; } else if (clazz.isObject()) { return "jsonb"; } else { throw new IllegalArgumentException(); } }
public static long parseTimestamp(Object timestampWithTimeZone) { if (timestampWithTimeZone instanceof Number) { return parseTimestamp((Number) timestampWithTimeZone); } else if (timestampWithTimeZone instanceof String) { String encoded = timestampWithTimeZone.toString(); // Joda parses [0-9]{10} as TIMESTAMP with huge value so we limit the characters. if (encoded.length() > 12) { parseTimestamp(encoded); } } throw new RuntimeException("Invalid TIMESTAMP"); }
createdAt = DateTimeUtils.parseTimestamp(o.getValue().isNumber() ? o.getValue().numberValue() : o.getValue().textValue()); } catch (Exception e) {
case TIMESTAMP: try { return new Timestamp(value.isNumber() ? DateTimeUtils.parseTimestamp(value.asLong()) : DateTimeUtils.parseTimestamp(value.textValue())); } catch (Exception e) { return null; return new Timestamp(DateTimeUtils.parseDate(value.textValue())); } catch (Exception e) { return null;
return DateTimeUtils.parseTimestamp(jp.getValueAsString()); } catch (Exception e) { return null; return DateTimeUtils.parseDate(jp.getValueAsString()); } catch (Exception e) { return null;
DateTimeUtils.parseDate(value); return FieldType.DATE; } catch (Exception e) { DateTimeUtils.parseTimestamp(value); return FieldType.TIMESTAMP; } catch (Exception e) {
return DateTimeUtils.parseTimestamp(jp.getValueAsString()); } catch (Exception e) { if (field.name().equals(projectConfig.getTimeColumn())) { return DateTimeUtils.parseDate(jp.getValueAsString()); } catch (Exception e) { if (field.name().equals(projectConfig.getTimeColumn())) {