Search in sources :

Example 36 with SimpleDateFormat

use of java.text.SimpleDateFormat in project storm by apache.

the class TestSimpleFileNameFormat method testParameters.

@Test
public void testParameters() {
    SimpleFileNameFormat format = new SimpleFileNameFormat().withName("$TIME.$HOST.$COMPONENT.$TASK.$NUM.txt").withPath("/mypath").withTimeFormat("yyyy-MM-dd HH:mm:ss");
    format.prepare(null, createTopologyContext());
    long now = System.currentTimeMillis();
    String path = format.getPath();
    String name = format.getName(1, now);
    Assert.assertEquals("/mypath", path);
    String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
    String host = null;
    try {
        host = Utils.localHostname();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    Assert.assertEquals(time + "." + host + ".Xcom.7.1.txt", name);
}
Also used : UnknownHostException(java.net.UnknownHostException) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 37 with SimpleDateFormat

use of java.text.SimpleDateFormat in project storm by apache.

the class TestSimpleFileNameFormat method testDefaults.

@Test
public void testDefaults() {
    SimpleFileNameFormat format = new SimpleFileNameFormat();
    format.prepare(null, createTopologyContext());
    long now = System.currentTimeMillis();
    String path = format.getPath();
    String name = format.getName(1, now);
    Assert.assertEquals("/storm", path);
    String time = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
    Assert.assertEquals(time + ".1.txt", name);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 38 with SimpleDateFormat

use of java.text.SimpleDateFormat in project storm by apache.

the class TestSimpleFileNameFormat method testDefaults.

@Test
public void testDefaults() {
    SimpleFileNameFormat format = new SimpleFileNameFormat();
    format.prepare(null, 3, 5);
    long now = System.currentTimeMillis();
    String path = format.getPath();
    String name = format.getName(1, now);
    Assert.assertEquals("/storm", path);
    String time = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
    Assert.assertEquals(time + ".1.txt", name);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 39 with SimpleDateFormat

use of java.text.SimpleDateFormat in project storm by apache.

the class TestSimpleFileNameFormat method testParameters.

@Test
public void testParameters() {
    SimpleFileNameFormat format = new SimpleFileNameFormat().withName("$TIME.$HOST.$PARTITION.$NUM.txt").withPath("/mypath").withTimeFormat("yyyy-MM-dd HH:mm:ss");
    format.prepare(null, 3, 5);
    long now = System.currentTimeMillis();
    String path = format.getPath();
    String name = format.getName(1, now);
    Assert.assertEquals("/mypath", path);
    String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now);
    String host = null;
    try {
        host = Utils.localHostname();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    Assert.assertEquals(time + "." + host + ".3.1.txt", name);
}
Also used : UnknownHostException(java.net.UnknownHostException) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 40 with SimpleDateFormat

use of java.text.SimpleDateFormat in project storm by apache.

the class DelimitedRecordHiveMapper method withTimeAsPartitionField.

public DelimitedRecordHiveMapper withTimeAsPartitionField(String timeFormat) {
    this.timeFormat = timeFormat;
    parseDate = new SimpleDateFormat(timeFormat);
    return this;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61