Search in sources :

Example 31 with SimpleDateFormat

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

the class SnapshotInfo method doWork.

@Override
public int doWork() throws IOException, InterruptedException {
    if (remoteDir != null) {
        URI defaultFs = remoteDir.getFileSystem(conf).getUri();
        FSUtils.setFsDefault(conf, new Path(defaultFs));
        FSUtils.setRootDir(conf, remoteDir);
    }
    // List Available Snapshots
    if (listSnapshots) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        System.out.printf("%-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME", "TABLE NAME");
        for (SnapshotDescription desc : getSnapshotList(conf)) {
            System.out.printf("%-20s | %20s | %s%n", desc.getName(), df.format(new Date(desc.getCreationTime())), desc.getTableNameAsString());
        }
        return 0;
    }
    rootDir = FSUtils.getRootDir(conf);
    fs = FileSystem.get(rootDir.toUri(), conf);
    LOG.debug("fs=" + fs.getUri().toString() + " root=" + rootDir);
    // Load snapshot information
    if (!loadSnapshotInfo(snapshotName)) {
        System.err.println("Snapshot '" + snapshotName + "' not found!");
        return 1;
    }
    printInfo();
    if (showSchema)
        printSchema();
    printFiles(showFiles, showStats);
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) URI(java.net.URI) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 32 with SimpleDateFormat

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

the class SnapshotInfo method printInfo.

/**
   * Dump the {@link SnapshotDescription}
   */
private void printInfo() {
    HBaseProtos.SnapshotDescription snapshotDesc = snapshotManifest.getSnapshotDescription();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    System.out.println("Snapshot Info");
    System.out.println("----------------------------------------");
    System.out.println("   Name: " + snapshotDesc.getName());
    System.out.println("   Type: " + snapshotDesc.getType());
    System.out.println("  Table: " + snapshotDesc.getTable());
    System.out.println(" Format: " + snapshotDesc.getVersion());
    System.out.println("Created: " + df.format(new Date(snapshotDesc.getCreationTime())));
    System.out.println("  Owner: " + snapshotDesc.getOwner());
    System.out.println();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) Date(java.util.Date)

Example 33 with SimpleDateFormat

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

the class TestNanoTimeUtils method testCompareDeprecatedNanoTimeWithNewNanoTime.

@Test
public void testCompareDeprecatedNanoTimeWithNewNanoTime() throws ParseException {
    Date d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2001-01-01 15:34:01.101");
    Timestamp knownTimestamp = new Timestamp(d.getTime());
    NanoTime newNTLocal = NanoTimeUtils.getNanoTime(knownTimestamp, Calendar.getInstance());
    NanoTime depNTLocal = NanoTimeUtils.getNanoTime(knownTimestamp, false);
    Assert.assertEquals(newNTLocal.getJulianDay(), depNTLocal.getJulianDay());
    Assert.assertEquals(newNTLocal.getTimeOfDayNanos(), depNTLocal.getTimeOfDayNanos());
    NanoTime newNTUTC = NanoTimeUtils.getNanoTime(knownTimestamp, Calendar.getInstance(TimeZone.getTimeZone("UTC")));
    NanoTime depNTUTC = NanoTimeUtils.getNanoTime(knownTimestamp, true);
    Assert.assertEquals(newNTUTC.getJulianDay(), depNTUTC.getJulianDay());
    Assert.assertEquals(newNTUTC.getTimeOfDayNanos(), depNTUTC.getTimeOfDayNanos());
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Example 34 with SimpleDateFormat

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

the class TestPrimitiveObjectInspectorUtils method testgetTimestampWithMillisecondsInt.

@Test
public void testgetTimestampWithMillisecondsInt() {
    DateFormat localDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    DateFormat gmtDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    PrimitiveObjectInspector voidOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.VOID);
    assertEquals(null, PrimitiveObjectInspectorUtils.getTimestamp(new Object(), voidOI));
    PrimitiveObjectInspector booleanOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.BOOLEAN);
    assertEquals("1970-01-01 00:00:00.001", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(true, booleanOI)));
    assertEquals("1970-01-01 00:00:00.000", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(false, booleanOI)));
    PrimitiveObjectInspector byteOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.BYTE);
    assertEquals("1970-01-01 00:00:00.001", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((byte) 1, byteOI)));
    assertEquals("1969-12-31 23:59:59.999", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((byte) -1, byteOI)));
    PrimitiveObjectInspector shortOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.SHORT);
    assertEquals("1970-01-01 00:00:00.001", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((short) 1, shortOI)));
    assertEquals("1969-12-31 23:59:59.999", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((short) -1, shortOI)));
    PrimitiveObjectInspector intOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.INT);
    assertEquals("1970-01-17 11:22:01.282", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((int) 1423321282, intOI)));
    assertEquals("1969-12-31 23:59:59.999", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((int) -1, intOI)));
    PrimitiveObjectInspector longOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.LONG);
    assertEquals("1970-01-17 11:22:01.282", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(1423321282L, longOI)));
    assertEquals("1969-12-31 23:59:59.999", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(-1L, longOI)));
    // Float loses some precisions
    PrimitiveObjectInspector floatOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.FLOAT);
    assertEquals("2015-02-07 15:02:24.000", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(1423321282.123f, floatOI)));
    assertEquals("1969-12-31 23:59:58.876", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(-1.123f, floatOI)));
    PrimitiveObjectInspector doubleOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.DOUBLE);
    assertEquals("2015-02-07 15:01:22.123", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((double) 1423321282.123, doubleOI)));
    assertEquals("1969-12-31 23:59:58.877", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp((double) -1.123, doubleOI)));
    PrimitiveObjectInspector decimalOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.DECIMAL);
    assertEquals("2015-02-07 15:01:22.000", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(HiveDecimal.create(1423321282L), decimalOI)));
    assertEquals("1969-12-31 23:59:59.000", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(HiveDecimal.create(-1), decimalOI)));
    PrimitiveObjectInspector stringOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.STRING);
    assertEquals("2015-02-07 15:01:22.123", localDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp("2015-02-07 15:01:22.123", stringOI)));
    PrimitiveObjectInspector charOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.CHAR);
    assertEquals("2015-02-07 15:01:22.123", localDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(new HiveChar("2015-02-07 15:01:22.123", 30), charOI)));
    PrimitiveObjectInspector varcharOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.VARCHAR);
    assertEquals("2015-02-07 15:01:22.123", localDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(new HiveVarchar("2015-02-07 15:01:22.123", 30), varcharOI)));
    PrimitiveObjectInspector dateOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.DATE);
    assertEquals("2015-02-07 00:00:00.000", localDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(new Date(1423321282123L), dateOI)));
    PrimitiveObjectInspector timestampOI = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.TIMESTAMP);
    assertEquals("2015-02-07 15:01:22.123", gmtDateFormat.format(PrimitiveObjectInspectorUtils.getTimestamp(new Timestamp(1423321282123L), timestampOI)));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) PrimitiveObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Date(java.sql.Date) Test(org.junit.Test)

Example 35 with SimpleDateFormat

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

the class SimpleFileNameFormat method getName.

@Override
public String getName(long rotation, long timeStamp) {
    // compile parameters
    SimpleDateFormat dateFormat = new SimpleDateFormat(timeFormat);
    String ret = name.replace("$TIME", dateFormat.format(new Date(timeStamp))).replace("$NUM", String.valueOf(rotation)).replace("$HOST", host).replace("$PARTITION", String.valueOf(partitionIndex));
    return ret;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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