Search in sources :

Example 11 with GregorianCalendar

use of java.util.GregorianCalendar in project flink by apache.

the class CollectionDataSets method getPojoWithCollection.

public static DataSet<PojoWithCollection> getPojoWithCollection(ExecutionEnvironment env) {
    List<PojoWithCollection> data = new ArrayList<>();
    List<Pojo1> pojosList1 = new ArrayList<>();
    pojosList1.add(new Pojo1("a", "aa"));
    pojosList1.add(new Pojo1("b", "bb"));
    List<Pojo1> pojosList2 = new ArrayList<>();
    pojosList2.add(new Pojo1("a2", "aa2"));
    pojosList2.add(new Pojo1("b2", "bb2"));
    PojoWithCollection pwc1 = new PojoWithCollection();
    pwc1.pojos = pojosList1;
    pwc1.key = 0;
    pwc1.bigInt = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN);
    pwc1.scalaBigInt = BigInt.int2bigInt(10);
    pwc1.bigDecimalKeepItNull = null;
    // use calendar to make it stable across time zones
    GregorianCalendar gcl1 = new GregorianCalendar(2033, 4, 18);
    pwc1.sqlDate = new java.sql.Date(gcl1.getTimeInMillis());
    pwc1.mixed = new ArrayList<>();
    Map<String, Integer> map = new HashMap<>();
    // map.put("anotherKey", 2); map.put("third", 3);
    map.put("someKey", 1);
    pwc1.mixed.add(map);
    pwc1.mixed.add(new File("/this/is/wrong"));
    pwc1.mixed.add("uhlala");
    PojoWithCollection pwc2 = new PojoWithCollection();
    pwc2.pojos = pojosList2;
    pwc2.key = 0;
    pwc2.bigInt = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN);
    pwc2.scalaBigInt = BigInt.int2bigInt(31104000);
    pwc2.bigDecimalKeepItNull = null;
    GregorianCalendar gcl2 = new GregorianCalendar(1976, 4, 3);
    // 1976
    pwc2.sqlDate = new java.sql.Date(gcl2.getTimeInMillis());
    data.add(pwc1);
    data.add(pwc2);
    return env.fromCollection(data);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) BigInteger(java.math.BigInteger) File(java.io.File)

Example 12 with GregorianCalendar

use of java.util.GregorianCalendar in project flink by apache.

the class ValueCollectionDataSets method getPojoWithCollection.

public static DataSet<PojoWithCollection> getPojoWithCollection(ExecutionEnvironment env) {
    List<PojoWithCollection> data = new ArrayList<>();
    List<Pojo1> pojosList1 = new ArrayList<>();
    pojosList1.add(new Pojo1("a", "aa"));
    pojosList1.add(new Pojo1("b", "bb"));
    List<Pojo1> pojosList2 = new ArrayList<>();
    pojosList2.add(new Pojo1("a2", "aa2"));
    pojosList2.add(new Pojo1("b2", "bb2"));
    PojoWithCollection pwc1 = new PojoWithCollection();
    pwc1.pojos = pojosList1;
    pwc1.key = new IntValue(0);
    pwc1.bigInt = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN);
    pwc1.scalaBigInt = BigInt.int2bigInt(10);
    pwc1.bigDecimalKeepItNull = null;
    // use calendar to make it stable across time zones
    GregorianCalendar gcl1 = new GregorianCalendar(2033, 04, 18);
    pwc1.sqlDate = new java.sql.Date(gcl1.getTimeInMillis());
    pwc1.mixed = new ArrayList<Object>();
    Map<StringValue, IntValue> map = new HashMap<>();
    map.put(new StringValue("someKey"), new IntValue(1));
    pwc1.mixed.add(map);
    pwc1.mixed.add(new File("/this/is/wrong"));
    pwc1.mixed.add("uhlala");
    PojoWithCollection pwc2 = new PojoWithCollection();
    pwc2.pojos = pojosList2;
    pwc2.key = new IntValue(0);
    pwc2.bigInt = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN);
    pwc2.scalaBigInt = BigInt.int2bigInt(31104000);
    pwc2.bigDecimalKeepItNull = null;
    GregorianCalendar gcl2 = new GregorianCalendar(1976, 4, 3);
    // 1976
    pwc2.sqlDate = new java.sql.Date(gcl2.getTimeInMillis());
    data.add(pwc1);
    data.add(pwc2);
    return env.fromCollection(data);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) File(java.io.File)

Example 13 with GregorianCalendar

use of java.util.GregorianCalendar in project hadoop by apache.

the class InvalidateBlocks method printBlockDeletionTime.

private void printBlockDeletionTime(final Logger log) {
    log.info(DFSConfigKeys.DFS_NAMENODE_STARTUP_DELAY_BLOCK_DELETION_SEC_KEY + " is set to " + DFSUtil.durationToString(pendingPeriodInMs));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMM dd HH:mm:ss");
    Calendar calendar = new GregorianCalendar();
    calendar.add(Calendar.SECOND, (int) (this.pendingPeriodInMs / 1000));
    log.info("The block deletion will start around " + sdf.format(calendar.getTime()));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with GregorianCalendar

use of java.util.GregorianCalendar in project kafka by apache.

the class JsonConverterTest method timeToConnect.

@Test
public void timeToConnect() {
    Schema schema = Time.SCHEMA;
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 14400000);
    java.util.Date reference = calendar.getTime();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1 }, \"payload\": 14400000 }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    java.util.Date converted = (java.util.Date) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
Also used : Schema(org.apache.kafka.connect.data.Schema) GregorianCalendar(java.util.GregorianCalendar) Date(org.apache.kafka.connect.data.Date) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Test(org.junit.Test)

Example 15 with GregorianCalendar

use of java.util.GregorianCalendar in project kafka by apache.

the class JsonConverterTest method dateToJson.

@Test
public void dateToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.DATE, 10000);
    java.util.Date date = calendar.getTime();
    JsonNode converted = parse(converter.fromConnectData(TOPIC, Date.SCHEMA, date));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"int32\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Date\", \"version\": 1 }"), converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
    JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertTrue(payload.isInt());
    assertEquals(10000, payload.intValue());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1212 Calendar (java.util.Calendar)574 Date (java.util.Date)358 Test (org.junit.Test)233 SimpleDateFormat (java.text.SimpleDateFormat)100 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)47 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)38 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)21 DateFormat (java.text.DateFormat)18 SQLException (java.sql.SQLException)17 Map (java.util.Map)16 Meeting (net.johnpwood.android.standuptimer.model.Meeting)16