Example usage for org.apache.hadoop.conf Configuration getBoolean

List of usage examples for org.apache.hadoop.conf Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getBoolean.

Prototype

public boolean getBoolean(String name, boolean defaultValue) 

Source Link

Document

Get the value of the name property as a boolean.

Usage

From source file:org.apache.lens.cube.parse.CubeQueryRewriter.java

License:Apache License

public CubeQueryRewriter(Configuration conf, HiveConf hconf) {
    this.conf = conf;
    this.hconf = hconf;
    try {/*from w  ww . ja v a2s  .  c o  m*/
        qlCtx = new Context(conf);
    } catch (IOException e) {
        // IOException is ignorable
    }
    lightFactFirst = conf.getBoolean(CubeQueryConfUtil.LIGHTEST_FACT_FIRST,
            CubeQueryConfUtil.DEFAULT_LIGHTEST_FACT_FIRST);
    setupRewriters();
}

From source file:org.apache.lens.cube.parse.GroupbyResolver.java

License:Apache License

GroupbyResolver(Configuration conf) {
    selectPromotionEnabled = conf.getBoolean(CubeQueryConfUtil.ENABLE_SELECT_TO_GROUPBY,
            CubeQueryConfUtil.DEFAULT_ENABLE_SELECT_TO_GROUPBY);
    groupbyPromotionEnabled = conf.getBoolean(CubeQueryConfUtil.ENABLE_GROUP_BY_TO_SELECT,
            CubeQueryConfUtil.DEFAULT_ENABLE_GROUP_BY_TO_SELECT);
}

From source file:org.apache.lens.cube.parse.MaxCoveringFactResolver.java

License:Apache License

MaxCoveringFactResolver(Configuration conf) {
    this.failOnPartialData = conf.getBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
}

From source file:org.apache.lens.cube.parse.StorageTableResolver.java

License:Apache License

StorageTableResolver(Configuration conf) {
    this.conf = conf;
    this.supportedStorages = getSupportedStorages(conf);
    this.allStoragesSupported = (supportedStorages == null);
    this.failOnPartialData = conf.getBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false);
    String str = conf.get(CubeQueryConfUtil.VALID_STORAGE_DIM_TABLES);
    validDimTables = StringUtils.isBlank(str) ? null : Arrays.asList(StringUtils.split(str.toLowerCase(), ","));
    this.processTimePartCol = conf.get(CubeQueryConfUtil.PROCESS_TIME_PART_COL);
    String maxIntervalStr = conf.get(CubeQueryConfUtil.QUERY_MAX_INTERVAL);
    if (maxIntervalStr != null) {
        this.maxInterval = UpdatePeriod.valueOf(maxIntervalStr);
    } else {/*from ww  w.  j a  v  a  2 s.  co m*/
        this.maxInterval = null;
    }
    rangeWriter = ReflectionUtils.newInstance(conf.getClass(CubeQueryConfUtil.TIME_RANGE_WRITER_CLASS,
            CubeQueryConfUtil.DEFAULT_TIME_RANGE_WRITER, TimeRangeWriter.class), this.conf);
    String formatStr = conf.get(CubeQueryConfUtil.PART_WHERE_CLAUSE_DATE_FORMAT);
    if (formatStr != null) {
        partWhereClauseFormat = new SimpleDateFormat(formatStr);
    }
    this.phase = PHASE.first();
    completenessThreshold = conf.getFloat(CubeQueryConfUtil.COMPLETENESS_THRESHOLD,
            CubeQueryConfUtil.DEFAULT_COMPLETENESS_THRESHOLD);
    completenessPartCol = conf.get(CubeQueryConfUtil.COMPLETENESS_CHECK_PART_COL);
}

From source file:org.apache.lens.driver.es.client.jest.JestClientImpl.java

License:Apache License

public JestClientImpl(ESDriverConfig esDriverConfig, Configuration conf) {
    super(esDriverConfig, conf);
    final JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(/*from w  w  w  .  j  a  v  a2s .co m*/
            new HttpClientConfig.Builder(Validate.notNull(conf.getStringCollection(ES_SERVERS)))
                    .maxTotalConnection(conf.getInt(MAX_TOTAL_CONN, DEFAULT_MAX_CONN))
                    .multiThreaded(conf.getBoolean(IS_MULTITHREADED, DEFAULT_MULTI_THREADED))
                    .readTimeout(esDriverConfig.getQueryTimeOutMs()).build());
    client = factory.getObject();
}

From source file:org.apache.lens.driver.hive.HiveDriver.java

License:Apache License

/**
 * Adds the persistent path.//from ww w .  ja v a2  s  .c  o m
 *
 * @param context the context
 * @throws IOException Signals that an I/O exception has occurred.
 */
void addPersistentPath(QueryContext context) throws IOException {
    String hiveQuery;
    Configuration qdconf = context.getDriverConf(this);
    boolean addInsertOverwrite = qdconf.getBoolean(LensConfConstants.QUERY_ADD_INSERT_OVEWRITE,
            LensConfConstants.DEFAULT_ADD_INSERT_OVEWRITE);
    if (context.isDriverPersistent() && addInsertOverwrite
            && (context.getSelectedDriverQuery().startsWith("SELECT")
                    || context.getSelectedDriverQuery().startsWith("select"))) {
        // store persistent data into user specified location
        // If absent, take default home directory
        Path resultSetPath = context.getHDFSResultDir();
        // create query
        StringBuilder builder = new StringBuilder("INSERT OVERWRITE DIRECTORY ");
        context.setDriverResultPath(
                resultSetPath.makeQualified(resultSetPath.getFileSystem(context.getConf())).toString());
        builder.append('"').append(resultSetPath).append("\" ");
        String outputDirFormat = qdconf.get(LensConfConstants.QUERY_OUTPUT_DIRECTORY_FORMAT);
        if (outputDirFormat != null) {
            builder.append(outputDirFormat);
        }
        builder.append(' ').append(context.getSelectedDriverQuery()).append(' ');
        hiveQuery = builder.toString();
    } else {
        context.unSetDriverPersistent();
        hiveQuery = context.getSelectedDriverQuery();
    }
    log.info("Hive driver {} query:{}", getFullyQualifiedName(), hiveQuery);
    context.setSelectedDriverQuery(hiveQuery);
}

From source file:org.apache.lens.driver.jdbc.DruidSQLRewriter.java

License:Apache License

public String rewrite(ASTNode currNode, Configuration conf, HiveConf metastoreConf, boolean resolveNativeTables)
        throws LensException {
    this.resolveNativeTables = resolveNativeTables;
    rewrittenQuery.setLength(0);//from  w w w .j  a  v a2s.co m
    reset();
    this.ast = currNode;
    isHavingSupported = conf.getBoolean(JDBCDriverConfConstants.JDBC_IS_HAVING_SUPPORTED,
            JDBCDriverConfConstants.DEFAULT_JDBC_IS_HAVING_SUPPORTED);
    isOrderBySupported = conf.getBoolean(JDBCDriverConfConstants.JDBC_IS_ORDERBY_SUPPORTED,
            JDBCDriverConfConstants.DEFAULT_JDBC_IS_ORDERBY_SUPPORTED);

    ASTNode fromNode = HQLParser.findNodeByPath(currNode, TOK_FROM);
    if (fromNode != null) {
        if (fromNode.getChild(0).getType() == TOK_SUBQUERY) {
            log.warn("Subqueries in from clause not supported by {} Query : {}", this, this.query);
            throw new LensException(
                    "Subqueries in from clause not supported by " + this + " Query : " + this.query);
        } else if (isOfTypeJoin(fromNode.getChild(0).getType())) {
            log.warn("Join in from clause not supported by {} Query : {}", this, this.query);
            throw new LensException("Join in from clause not supported by " + this + " Query : " + this.query);
        }
    }

    if (currNode.getToken().getType() == TOK_UNIONALL) {
        log.warn("Union queries are not supported by {} Query : {}", this, this.query);
        throw new LensException("Union queries are not supported by " + this + " Query : " + this.query);
    }

    if (!isHavingSupported
            && HQLParser.findNodeByPath(currNode, HiveParser.TOK_INSERT, HiveParser.TOK_HAVING) != null) {
        log.warn("Having queries are not supported by {} Query : {}", this, this.query);
        throw new LensException("Having queries are not supported by " + this + " Query : " + this.query);
    }

    if (!isOrderBySupported
            && HQLParser.findNodeByPath(currNode, HiveParser.TOK_INSERT, HiveParser.TOK_ORDERBY) != null) {
        log.warn("Order by queries are not supported by {} Query : {}", this, this.query);
        throw new LensException("Order by queries are not supported by " + this + " Query : " + this.query);
    }

    String rewritternQueryText = rewrittenQuery.toString();
    if (currNode.getToken().getType() == TOK_QUERY) {
        try {
            buildDruidQuery(conf, metastoreConf);
            rewritternQueryText = rewrittenQuery.toString();
            log.info("Rewritten query from build : " + rewritternQueryText);
        } catch (SemanticException e) {
            throw new LensException(e);
        }
    }
    return rewritternQueryText;
}

From source file:org.apache.lens.driver.jdbc.JDBCDriver.java

License:Apache License

/**
 * Explain the given query.//from  w  w w.  j  a  va 2s  .  co m
 *
 * @param explainCtx The explain context
 * @return The query plan object;
 * @throws LensException the lens exception
 */
@Override
public DriverQueryPlan explain(AbstractQueryContext explainCtx) throws LensException {
    if (explainCtx.getDriverQuery(this) == null) {
        throw new NullPointerException("Null driver query for " + explainCtx.getUserQuery());
    }
    if (explainCtx.getDriverContext().getDriverQueryPlan(this) != null) {
        // explain called again and again
        return explainCtx.getDriverContext().getDriverQueryPlan(this);
    }
    checkConfigured();
    String explainQuery;
    String rewrittenQuery = rewriteQuery(explainCtx);
    Configuration explainConf = explainCtx.getDriverConf(this);
    String explainKeyword = explainConf.get(JDBC_EXPLAIN_KEYWORD_PARAM, DEFAULT_JDBC_EXPLAIN_KEYWORD);
    boolean explainBeforeSelect = explainConf.getBoolean(JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT,
            DEFAULT_JDBC_EXPLAIN_KEYWORD_BEFORE_SELECT);

    if (explainBeforeSelect) {
        explainQuery = explainKeyword + " " + rewrittenQuery;
    } else {
        explainQuery = rewrittenQuery.replaceAll("select ", "select " + explainKeyword + " ");
    }
    log.info("{} Explain Query : {}", getFullyQualifiedName(), explainQuery);
    QueryContext explainQueryCtx = QueryContext.createContextWithSingleDriver(explainQuery, null,
            new LensConf(), explainConf, this, explainCtx.getLensSessionIdentifier(), false);
    QueryResult result = null;
    try {
        result = executeInternal(explainQueryCtx, explainQuery);
        if (result.error != null) {
            throw new LensException("Query explain failed!", result.error);
        }
    } finally {
        if (result != null) {
            result.close();
        }
    }
    JDBCQueryPlan jqp = new JDBCQueryPlan();
    explainCtx.getDriverContext().setDriverQueryPlan(this, jqp);
    return jqp;
}

From source file:org.apache.lens.lib.query.LensFileOutputFormat.java

License:Apache License

/**
 * Gets the compress output.//from w  ww.ja va  2s  . co m
 *
 * @param conf the conf
 * @return the compress output
 */
public static boolean getCompressOutput(Configuration conf) {
    return conf.getBoolean(LensConfConstants.QUERY_OUTPUT_ENABLE_COMPRESSION,
            LensConfConstants.DEFAULT_OUTPUT_ENABLE_COMPRESSION);
}

From source file:org.apache.lens.server.api.query.AbstractQueryContext.java

License:Apache License

protected AbstractQueryContext(final String query, final String user, final LensConf qconf,
        final Configuration conf, final Collection<LensDriver> drivers, boolean mergeDriverConf) {
    if (conf.getBoolean(LensConfConstants.ENABLE_QUERY_METRICS,
            LensConfConstants.DEFAULT_ENABLE_QUERY_METRICS)) {
        UUID metricId = UUID.randomUUID();
        conf.set(LensConfConstants.QUERY_METRIC_UNIQUE_ID_CONF_KEY, metricId.toString());
        log.info("Generated metric id: {} for query: {}", metricId, query);
    }/*from www. j  av  a 2s . com*/
    driverContext = new DriverSelectorQueryContext(query, conf, drivers, mergeDriverConf);
    userQuery = query;
    phase1RewrittenQuery = query;
    this.lensConf = qconf;
    this.conf = conf;
    this.submittedUser = user;
    // we are setting selectedDriverQuery as user query only when the drivers size is 1
    // if drivers size is more than the driver query will be set after selection over drivers
    if (drivers != null && drivers.size() == 1) {
        this.selectedDriverQuery = query;
        setSelectedDriver(drivers.iterator().next());
    }

    // If this is created under an 'acquire' current db would be set
    if (SessionState.get() != null) {
        String currDb = SessionState.get().getCurrentDatabase();
        database = currDb == null ? "default" : currDb;
    } else {
        database = "default";
    }
}