Example usage for org.joda.time DateTimeZone getDefault

List of usage examples for org.joda.time DateTimeZone getDefault

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getDefault.

Prototype

public static DateTimeZone getDefault() 

Source Link

Document

Gets the default time zone.

Usage

From source file:com.facebook.presto.hive.HiveMetadataFactory.java

License:Apache License

public HiveMetadataFactory(HiveConnectorId connectorId, ExtendedHiveMetastore metastore,
        HdfsEnvironment hdfsEnvironment, HivePartitionManager partitionManager, DateTimeZone timeZone,
        int maxConcurrentFileRenames, boolean allowCorruptWritesForTesting, boolean respectTableFormat,
        boolean skipDeletionForAlter, boolean bucketWritingEnabled, HiveStorageFormat defaultStorageFormat,
        long perTransactionCacheMaximumSize, TypeManager typeManager, LocationService locationService,
        TableParameterCodec tableParameterCodec, JsonCodec<PartitionUpdate> partitionUpdateCodec,
        ExecutorService executorService, TypeTranslator typeTranslator, String prestoVersion) {
    this.connectorId = requireNonNull(connectorId, "connectorId is null").toString();

    this.allowCorruptWritesForTesting = allowCorruptWritesForTesting;
    this.respectTableFormat = respectTableFormat;
    this.skipDeletionForAlter = skipDeletionForAlter;
    this.bucketWritingEnabled = bucketWritingEnabled;
    this.defaultStorageFormat = requireNonNull(defaultStorageFormat, "defaultStorageFormat is null");
    this.perTransactionCacheMaximumSize = perTransactionCacheMaximumSize;

    this.metastore = requireNonNull(metastore, "metastore is null");
    this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null");
    this.partitionManager = requireNonNull(partitionManager, "partitionManager is null");
    this.timeZone = requireNonNull(timeZone, "timeZone is null");
    this.typeManager = requireNonNull(typeManager, "typeManager is null");
    this.locationService = requireNonNull(locationService, "locationService is null");
    this.tableParameterCodec = requireNonNull(tableParameterCodec, "tableParameterCodec is null");
    this.partitionUpdateCodec = requireNonNull(partitionUpdateCodec, "partitionUpdateCodec is null");
    this.typeTranslator = requireNonNull(typeTranslator, "typeTranslator is null");
    this.prestoVersion = requireNonNull(prestoVersion, "prestoVersion is null");

    if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) {
        log.warn("Hive writes are disabled. "
                + "To write data to Hive, your JVM timezone must match the Hive storage timezone. "
                + "Add -Duser.timezone=%s to your JVM arguments", timeZone.getID());
    }/*from  w  ww . j  a v  a 2s .  c o  m*/

    renameExecution = new BoundedExecutor(executorService, maxConcurrentFileRenames);
}

From source file:com.facebook.presto.hive.HiveQueryRunner.java

License:Apache License

public static DistributedQueryRunner createQueryRunner(Iterable<TpchTable<?>> tables,
        Map<String, String> extraProperties, String security, Map<String, String> extraHiveProperties)
        throws Exception {
    assertEquals(DateTimeZone.getDefault(), TIME_ZONE,
            "Timezone not configured correctly. Add -Duser.timezone=Asia/Katmandu to your JVM arguments");

    DistributedQueryRunner queryRunner = new DistributedQueryRunner(createSession(), 4, extraProperties);

    try {// ww w .  jav a2 s.com
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");

        File baseDir = queryRunner.getCoordinator().getBaseDataDir().resolve("hive_data").toFile();
        InMemoryHiveMetastore metastore = new InMemoryHiveMetastore(baseDir);
        metastore.setUserRoles(createSession().getUser(), ImmutableSet.of(ADMIN_ROLE_NAME));
        metastore.createDatabase(createDatabaseMetastoreObject(baseDir, TPCH_SCHEMA));
        metastore.createDatabase(createDatabaseMetastoreObject(baseDir, TPCH_BUCKETED_SCHEMA));
        queryRunner.installPlugin(new HivePlugin(HIVE_CATALOG, new BridgingHiveMetastore(metastore)));

        metastore.setUserRoles(createSession().getUser(), ImmutableSet.of("admin"));

        Map<String, String> hiveProperties = ImmutableMap.<String, String>builder().putAll(extraHiveProperties)
                .put("hive.metastore.uri", "thrift://localhost:8080").put("hive.time-zone", TIME_ZONE.getID())
                .put("hive.security", security).build();
        Map<String, String> hiveBucketedProperties = ImmutableMap.<String, String>builder()
                .putAll(hiveProperties).put("hive.max-initial-split-size", "10kB") // so that each bucket has multiple splits
                .put("hive.max-split-size", "10kB") // so that each bucket has multiple splits
                .put("hive.storage-format", "TEXTFILE") // so that there's no minimum split size for the file
                .put("hive.compression-codec", "NONE") // so that the file is splittable
                .build();
        queryRunner.createCatalog(HIVE_CATALOG, HIVE_CATALOG, hiveProperties);
        queryRunner.createCatalog(HIVE_BUCKETED_CATALOG, HIVE_CATALOG, hiveBucketedProperties);

        copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, createSession(), tables);
        copyTpchTablesBucketed(queryRunner, "tpch", TINY_SCHEMA_NAME, createBucketedSession(), tables);

        return queryRunner;
    } catch (Exception e) {
        queryRunner.close();
        throw e;
    }
}

From source file:com.facebook.presto.hive.HiveWriteUtils.java

License:Apache License

public static Object getField(Type type, Block block, int position) {
    if (block.isNull(position)) {
        return null;
    }//from   w  ww . j av a 2s. co  m
    if (BooleanType.BOOLEAN.equals(type)) {
        return type.getBoolean(block, position);
    }
    if (BigintType.BIGINT.equals(type)) {
        return type.getLong(block, position);
    }
    if (IntegerType.INTEGER.equals(type)) {
        return (int) type.getLong(block, position);
    }
    if (SmallintType.SMALLINT.equals(type)) {
        return (short) type.getLong(block, position);
    }
    if (TinyintType.TINYINT.equals(type)) {
        return (byte) type.getLong(block, position);
    }
    if (RealType.REAL.equals(type)) {
        return intBitsToFloat((int) type.getLong(block, position));
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return type.getDouble(block, position);
    }
    if (type instanceof VarcharType) {
        return new Text(type.getSlice(block, position).getBytes());
    }
    if (type instanceof CharType) {
        CharType charType = (CharType) type;
        return new Text(padEnd(type.getSlice(block, position).toStringUtf8(), charType.getLength(), ' '));
    }
    if (VarbinaryType.VARBINARY.equals(type)) {
        return type.getSlice(block, position).getBytes();
    }
    if (DateType.DATE.equals(type)) {
        long days = type.getLong(block, position);
        return new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), TimeUnit.DAYS.toMillis(days)));
    }
    if (TimestampType.TIMESTAMP.equals(type)) {
        long millisUtc = type.getLong(block, position);
        return new Timestamp(millisUtc);
    }
    if (type instanceof DecimalType) {
        DecimalType decimalType = (DecimalType) type;
        return getHiveDecimal(decimalType, block, position);
    }
    if (isArrayType(type)) {
        Type elementType = type.getTypeParameters().get(0);

        Block arrayBlock = block.getObject(position, Block.class);

        List<Object> list = new ArrayList<>(arrayBlock.getPositionCount());
        for (int i = 0; i < arrayBlock.getPositionCount(); i++) {
            Object element = getField(elementType, arrayBlock, i);
            list.add(element);
        }

        return Collections.unmodifiableList(list);
    }
    if (isMapType(type)) {
        Type keyType = type.getTypeParameters().get(0);
        Type valueType = type.getTypeParameters().get(1);

        Block mapBlock = block.getObject(position, Block.class);
        Map<Object, Object> map = new HashMap<>();
        for (int i = 0; i < mapBlock.getPositionCount(); i += 2) {
            Object key = getField(keyType, mapBlock, i);
            Object value = getField(valueType, mapBlock, i + 1);
            map.put(key, value);
        }

        return Collections.unmodifiableMap(map);
    }
    if (isRowType(type)) {
        Block rowBlock = block.getObject(position, Block.class);

        List<Type> fieldTypes = type.getTypeParameters();
        checkCondition(fieldTypes.size() == rowBlock.getPositionCount(),
                StandardErrorCode.GENERIC_INTERNAL_ERROR,
                "Expected row value field count does not match type field count");

        List<Object> row = new ArrayList<>(rowBlock.getPositionCount());
        for (int i = 0; i < rowBlock.getPositionCount(); i++) {
            Object element = getField(fieldTypes.get(i), rowBlock, i);
            row.add(element);
        }

        return Collections.unmodifiableList(row);
    }
    throw new PrestoException(NOT_SUPPORTED, "unsupported type: " + type);
}

From source file:com.facebook.presto.hive.parquet.AbstractTestParquetReader.java

License:Apache License

@BeforeClass
public void setUp() {
    assertEquals(DateTimeZone.getDefault(), HIVE_STORAGE_TIME_ZONE);
    setParquetLogging();
}

From source file:com.facebook.presto.orc.AbstractTestOrcReader.java

License:Apache License

@BeforeClass
public void setUp() {
    assertEquals(DateTimeZone.getDefault(), HIVE_STORAGE_TIME_ZONE);
}

From source file:com.facebook.presto.plugin.jdbc.JdbcPageSink.java

License:Apache License

private void appendColumn(Page page, int position, int channel) throws SQLException {
    Block block = page.getBlock(channel);
    int parameter = channel + 1;

    if (block.isNull(position)) {
        statement.setObject(parameter, null);
        return;//from   ww w  .j  a  v a  2s  . com
    }

    Type type = columnTypes.get(channel);
    if (BOOLEAN.equals(type)) {
        statement.setBoolean(parameter, type.getBoolean(block, position));
    } else if (BIGINT.equals(type)) {
        statement.setLong(parameter, type.getLong(block, position));
    } else if (INTEGER.equals(type)) {
        statement.setInt(parameter, toIntExact(type.getLong(block, position)));
    } else if (SMALLINT.equals(type)) {
        statement.setShort(parameter, Shorts.checkedCast(type.getLong(block, position)));
    } else if (TINYINT.equals(type)) {
        statement.setByte(parameter, SignedBytes.checkedCast(type.getLong(block, position)));
    } else if (DOUBLE.equals(type)) {
        statement.setDouble(parameter, type.getDouble(block, position));
    } else if (REAL.equals(type)) {
        statement.setFloat(parameter, intBitsToFloat(toIntExact(type.getLong(block, position))));
    } else if (type instanceof DecimalType) {
        statement.setBigDecimal(parameter, readBigDecimal((DecimalType) type, block, position));
    } else if (isVarcharType(type) || isCharType(type)) {
        statement.setString(parameter, type.getSlice(block, position).toStringUtf8());
    } else if (VARBINARY.equals(type)) {
        statement.setBytes(parameter, type.getSlice(block, position).getBytes());
    } else if (DATE.equals(type)) {
        // convert to midnight in default time zone
        long utcMillis = DAYS.toMillis(type.getLong(block, position));
        long localMillis = getInstanceUTC().getZone().getMillisKeepLocal(DateTimeZone.getDefault(), utcMillis);
        statement.setDate(parameter, new Date(localMillis));
    } else {
        throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
    }
}

From source file:com.facebook.presto.plugin.jdbc.JdbcRecordSink.java

License:Apache License

@Override
public void appendLong(long value) {
    try {/*from w  ww  .  ja  v a2  s .co m*/
        if (DATE.equals(columnTypes.get(field))) {
            // convert to midnight in default time zone
            long utcMillis = TimeUnit.DAYS.toMillis(value);
            long localMillis = ISOChronology.getInstanceUTC().getZone()
                    .getMillisKeepLocal(DateTimeZone.getDefault(), utcMillis);
            statement.setDate(next(), new Date(localMillis));
        } else {
            statement.setLong(next(), value);
        }
    } catch (SQLException e) {
        throw new PrestoException(JDBC_ERROR, e);
    }
}

From source file:com.facebook.presto.plugin.jdbc.QueryBuilder.java

License:Apache License

public PreparedStatement buildSql(JdbcClient client, Connection connection, String catalog, String schema,
        String table, List<JdbcColumnHandle> columns, TupleDomain<ColumnHandle> tupleDomain)
        throws SQLException {
    StringBuilder sql = new StringBuilder();

    String columnNames = columns.stream().map(JdbcColumnHandle::getColumnName).map(this::quote)
            .collect(joining(", "));

    sql.append("SELECT ");
    sql.append(columnNames);/* w w  w  . ja  v a2  s.c  om*/
    if (columns.isEmpty()) {
        sql.append("null");
    }

    sql.append(" FROM ");
    if (!isNullOrEmpty(catalog)) {
        sql.append(quote(catalog)).append('.');
    }
    if (!isNullOrEmpty(schema)) {
        sql.append(quote(schema)).append('.');
    }
    sql.append(quote(table));

    List<TypeAndValue> accumulator = new ArrayList<>();

    List<String> clauses = toConjuncts(columns, tupleDomain, accumulator);
    if (!clauses.isEmpty()) {
        sql.append(" WHERE ").append(Joiner.on(" AND ").join(clauses));
    }

    PreparedStatement statement = client.getPreparedStatement(connection, sql.toString());

    for (int i = 0; i < accumulator.size(); i++) {
        TypeAndValue typeAndValue = accumulator.get(i);
        if (typeAndValue.getType().equals(BigintType.BIGINT)) {
            statement.setLong(i + 1, (long) typeAndValue.getValue());
        } else if (typeAndValue.getType().equals(IntegerType.INTEGER)) {
            statement.setInt(i + 1, ((Number) typeAndValue.getValue()).intValue());
        } else if (typeAndValue.getType().equals(SmallintType.SMALLINT)) {
            statement.setShort(i + 1, ((Number) typeAndValue.getValue()).shortValue());
        } else if (typeAndValue.getType().equals(TinyintType.TINYINT)) {
            statement.setByte(i + 1, ((Number) typeAndValue.getValue()).byteValue());
        } else if (typeAndValue.getType().equals(DoubleType.DOUBLE)) {
            statement.setDouble(i + 1, (double) typeAndValue.getValue());
        } else if (typeAndValue.getType().equals(RealType.REAL)) {
            statement.setFloat(i + 1, intBitsToFloat(((Number) typeAndValue.getValue()).intValue()));
        } else if (typeAndValue.getType().equals(BooleanType.BOOLEAN)) {
            statement.setBoolean(i + 1, (boolean) typeAndValue.getValue());
        } else if (typeAndValue.getType().equals(DateType.DATE)) {
            long millis = DAYS.toMillis((long) typeAndValue.getValue());
            statement.setDate(i + 1, new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millis)));
        } else if (typeAndValue.getType().equals(TimeType.TIME)) {
            statement.setTime(i + 1, new Time((long) typeAndValue.getValue()));
        } else if (typeAndValue.getType().equals(TimeWithTimeZoneType.TIME_WITH_TIME_ZONE)) {
            statement.setTime(i + 1, new Time(unpackMillisUtc((long) typeAndValue.getValue())));
        } else if (typeAndValue.getType().equals(TimestampType.TIMESTAMP)) {
            statement.setTimestamp(i + 1, new Timestamp((long) typeAndValue.getValue()));
        } else if (typeAndValue.getType().equals(TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE)) {
            statement.setTimestamp(i + 1, new Timestamp(unpackMillisUtc((long) typeAndValue.getValue())));
        } else if (typeAndValue.getType() instanceof VarcharType) {
            statement.setString(i + 1, ((Slice) typeAndValue.getValue()).toStringUtf8());
        } else {
            throw new UnsupportedOperationException("Can't handle type: " + typeAndValue.getType());
        }
    }

    return statement;
}

From source file:com.facebook.presto.rcfile.AbstractTestRcFileReader.java

License:Apache License

@BeforeClass
public void setUp() {
    assertEquals(DateTimeZone.getDefault(), RcFileTester.HIVE_STORAGE_TIME_ZONE);
}

From source file:com.facebook.presto.tests.H2QueryRunner.java

License:Apache License

public MaterializedResult execute(Session session, @Language("SQL") String sql,
        List<? extends Type> resultTypes) {
    MaterializedResult materializedRows = new MaterializedResult(
            handle.createQuery(sql).map(rowMapper(resultTypes)).list(), resultTypes);

    // H2 produces dates in the JVM time zone instead of the session timezone
    materializedRows = materializedRows.toTimeZone(DateTimeZone.getDefault(),
            getDateTimeZone(session.getTimeZoneKey()));

    return materializedRows;
}