Package org.apache.tajo.benchmark

Source Code of org.apache.tajo.benchmark.BenchmarkSet

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.tajo.benchmark;

import com.google.protobuf.ServiceException;
import org.apache.hadoop.net.NetUtils;
import org.apache.tajo.catalog.CatalogConstants;
import org.apache.tajo.catalog.Schema;
import org.apache.tajo.catalog.store.MemStore;
import org.apache.tajo.client.TajoClient;
import org.apache.tajo.conf.TajoConf;
import org.apache.tajo.conf.TajoConf.ConfVars;
import org.apache.tajo.util.FileUtil;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public abstract class BenchmarkSet {
  protected TajoClient tajo;
  protected Map<String, Schema> schemas = new HashMap<String, Schema>();
  protected Map<String, Schema> outSchemas = new HashMap<String, Schema>();
  protected Map<String, String> queries = new HashMap<String, String>();
  protected String dataDir;

  public void init(TajoConf conf, String dataDir) throws IOException {
    this.dataDir = dataDir;
    if (System.getProperty(ConfVars.WORKER_PEER_RPC_ADDRESS.varname) != null) {
      tajo = new TajoClient(NetUtils.createSocketAddr(
          System.getProperty(ConfVars.WORKER_PEER_RPC_ADDRESS.varname)));
    } else {
      conf.set(CatalogConstants.STORE_CLASS, MemStore.class.getCanonicalName());
      tajo = new TajoClient(conf);
    }
  }

  protected void loadQueries(String dir) throws IOException {
    // TODO - this code dead??
    File queryDir = new File(dir);

    if(!queryDir.exists()) {
      queryDir = new File(System.getProperty("user.dir") + "/tajo-core/tajo-core-backend/" + dir);
    }

    if(!queryDir.exists())
    {
      return;
    }
    int last;
    String name, query;
    for (String file : queryDir.list()) {
      if (file.endsWith(".sql")) {
        last = file.indexOf(".sql");
        name = file.substring(0, last);
        query = FileUtil.readTextFile(new File(queryDir + "/" + file));
      }
    }
  }

  public abstract void loadSchemas();

  public abstract void loadOutSchema();

  public abstract void loadQueries() throws IOException;

  public abstract void loadTables() throws ServiceException;

  public String [] getTableNames() {
    return schemas.keySet().toArray(new String[schemas.size()]);
  }

  public String getQuery(String queryName) {
    return queries.get(queryName);
  }

  public Schema getSchema(String name) {
    return schemas.get(name);
  }

  public Iterable<Schema> getSchemas() {
    return schemas.values();
  }

  public Schema getOutSchema(String name) {
    return outSchemas.get(name);
  }

  public void perform(String queryName) throws IOException, ServiceException {
    String query = getQuery(queryName);
    if (query == null) {
      throw new IllegalArgumentException("#{queryName} does not exists");
    }
    long start = System.currentTimeMillis();
    tajo.executeQuery(query);
    long end = System.currentTimeMillis();

    System.out.println("====================================");
    System.out.println("QueryName: " + queryName);
    System.out.println("Query: " + query);
    System.out.println("Processing Time: " + (end - start));
    System.out.println("====================================");
  }
}
TOP

Related Classes of org.apache.tajo.benchmark.BenchmarkSet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.