Package com.alibaba.wasp.plan.parser

Examples of com.alibaba.wasp.plan.parser.ParseContext


      "CREATE index PhotosByTag on Photo(tag);" };

  public static void loadTable(Configuration conf) throws MetaException, ZooKeeperConnectionException {
    MemFMetaStore fmetaServices = new MemFMetaStore();
    TableSchemaCacheReader reader = TableSchemaCacheReader.getInstance(conf, fmetaServices);
    ParseContext context = new ParseContext();
    context.setTsr(reader);
    DruidDQLParser dqlParser = new DruidDQLParser(conf, null);
    DruidDDLParser ddlParser = new DruidDDLParser(conf);
    DruidDMLParser dmlParser = new DruidDMLParser(conf, null);
    WaspParser druidParser = new WaspParser(ddlParser, dqlParser, dmlParser);
View Full Code Here


  @Test
  public void testExecInsertPlan() throws ServiceException, IOException {
    String sql = "Insert into " + TABLE_NAME
        + " (column1,column2,column3) values (123,456,'abc');";
    ParseContext context = new ParseContext();
    context.setTsr(TableSchemaCacheReader.getInstance(TEST_UTIL
        .getConfiguration()));
    context.setSql(sql);
    context.setReadModel(ReadModel.CURRENT);
    parser.generatePlan(context);

    InsertPlan plan = (InsertPlan) context.getPlan();
    List<WriteResultProto> writeResultProtos = engine.execInsertPlan(plan);
    assertTrue(writeResultProtos.size() == 1);

    for (ClientProtos.WriteResultProto writeResultProto : writeResultProtos) {
      assertTrue(writeResultProto.getCode() == ClientProtos.WriteResultProto.StatusCode.SUCCESS);
View Full Code Here

   * @throws com.google.protobuf.ServiceException
   */
  private void testExecQueryPlan(String sql, boolean exits)
      throws ServiceException, IOException {

    ParseContext context = new ParseContext();
    context.setTsr(TableSchemaCacheReader.getInstance(TEST_UTIL
        .getConfiguration()));
    context.setSql(sql);
    context.setReadModel(ReadModel.CURRENT);
    parser.generatePlan(context);

    LocalQueryPlan plan = (LocalQueryPlan) context.getPlan();

    Pair<Boolean, Pair<String, Pair<List<QueryResultProto>, List<StringDataTypePair>>>> rets = engine
        .execQueryPlan(plan, "", false);
    if (!exits) {
      assertTrue(rets.getSecond().getSecond().getFirst().size() == 0);
View Full Code Here

  @Test
  public void testExecUpdatePlan() throws ServiceException, IOException {
    String sql = "UPDATE " + TABLE_NAME
        + " SET column3 = 'def' WHERE column1 = 123 and column2=456;";
    ParseContext context = new ParseContext();
    context.setTsr(TableSchemaCacheReader.getInstance(TEST_UTIL
        .getConfiguration()));
    context.setSql(sql);
    context.setReadModel(ReadModel.CURRENT);
    parser.generatePlan(context);

    UpdatePlan plan = (UpdatePlan) context.getPlan();
    List<WriteResultProto> writeResultProtos = engine.execUpdatePlan(plan);
    assertTrue(writeResultProtos.size() == 1);

    for (ClientProtos.WriteResultProto writeResultProto : writeResultProtos) {
      assertTrue(writeResultProto.getCode() == ClientProtos.WriteResultProto.StatusCode.SUCCESS);
View Full Code Here

  @Test
  public void testExecDeletePlan() throws ServiceException, IOException {
    String sql = "delete from " + TABLE_NAME
        + " where column1=123 and column2=456;";
    ParseContext context = new ParseContext();
    context.setTsr(TableSchemaCacheReader.getInstance(TEST_UTIL
        .getConfiguration()));
    context.setSql(sql);
    context.setReadModel(ReadModel.CURRENT);
    parser.generatePlan(context);

    DeletePlan plan = (DeletePlan) context.getPlan();
    List<WriteResultProto> writeResultProtos = engine.execDeletePlan(plan);
    assertTrue(writeResultProtos.size() == 1);

    for (ClientProtos.WriteResultProto writeResultProto : writeResultProtos) {
      assertTrue(writeResultProto.getCode() == ClientProtos.WriteResultProto.StatusCode.SUCCESS);
View Full Code Here

    List<String> sqls = new ArrayList<String>();
    sqls.add("Insert into User(user_id,name) values(1,'binlijin');");
    sqls.add("Insert into Photo(user_id,photo_id,tag) values(1,1,'tag');");

    for (String sql : sqls) {
      ParseContext context = new ParseContext();
      context.setGenWholePlan(false);
      context.setTsr(reader);
      context.setSql(sql);
      try {
        druidParser.generatePlan(context);
      } catch (RuntimeException e) {
        if (e instanceof ParserException || e instanceof SQLParseException) {
          throw new DoNotRetryIOException(e.getMessage(), e);
        } else {
          throw new ServiceException(new IOException(e));
        }
      } catch (UnsupportedException e) {
        throw e;
      }
      Plan executePlan = context.getPlan();
      if (executePlan instanceof DMLPlan) {
        dmlPlans.add((DMLPlan) executePlan);
      } else {
        // TODO throw exception
      }
    }

    ParseContext context = new ParseContext();
    context.setTsr(reader);

    DMLTransactionPlan transactionPlan = WaspParser.generateTransactionPlan(
        context, dmlPlans);
    return transactionPlan;
  }
View Full Code Here

  public ClientProtos.ExecuteResponse execute(String sql, String sessionId,
      ReadModel readModel, boolean closeSession, int fetchSize)
      throws ServiceException {
    try {
      long beforeGenPlan = EnvironmentEdgeManager.currentTimeMillis();
      ParseContext context = new ParseContext();
      context.setTsr(TableSchemaCacheReader.getInstance(service
          .getConfiguration()));
      context.setSql(sql);
      context.setReadModel(readModel);
      context.setSessionId(sessionId);
      try {
        if (StringUtils.isNotEmpty(sessionId)) {
          Parser.SQLType sqlType = parser.getSQLType(context);
          if(sqlType == Parser.SQLType.DQL) {
            context.setPlan(new DQLPlan());
          } else {
            parser.generatePlan(context);
          }
        } else {
          parser.generatePlan(context);
        }
      } catch (RuntimeException e) {
        if (e instanceof ParserException || e instanceof SQLParseException) {
          throw new DoNotRetryIOException(e.getMessage(), e);
        } else {
          throw new ServiceException(new IOException(e));
        }
      } catch (UnsupportedException e) {
        throw e;
      }
      final long afterGenPlan = EnvironmentEdgeManager.currentTimeMillis();
      ((FServer) this.service).getMetrics().updateGenPlan(
          afterGenPlan - beforeGenPlan);

      Plan executePlan = context.getPlan();
      if (executePlan instanceof DQLPlan) {
        selectSQLCount.increment();
        DQLPlan dqlPlan = (DQLPlan) executePlan;
        dqlPlan.setFetchRows(fetchSize);
        Pair<Boolean, Pair<String, Pair<List<QueryResultProto>, List<StringDataTypePair>>>> queryResults =
View Full Code Here

  public ExecuteResponse execute(List<String> sqls, boolean isTransaction, String sessionId) throws ServiceException {
    try {
      long beforeGenPlan = EnvironmentEdgeManager.currentTimeMillis();
      List<DMLPlan> dmlPlans = new ArrayList<DMLPlan>();
      for (String sql : sqls) {
        ParseContext context = new ParseContext();
        context.setTsr(TableSchemaCacheReader.getInstance(service
            .getConfiguration()));
        context.setSql(sql);
        context.setSessionId(sessionId);
        try {
            parser.generatePlan(context);
        } catch (RuntimeException e) {
          if (e instanceof ParserException || e instanceof SQLParseException) {
            throw new DoNotRetryIOException(e.getMessage(), e);
          } else {
            throw new ServiceException(new IOException(e));
          }
        } catch (UnsupportedException e) {
          throw e;
        }
        Plan executePlan = context.getPlan();
        if(executePlan instanceof DMLPlan) {
          dmlPlans.add((DMLPlan) executePlan);
        } else {
          //TODO throw exception
        }
      }

      ParseContext context = new ParseContext();
      context.setTsr(TableSchemaCacheReader.getInstance(service
          .getConfiguration()));
      context.setSessionId(sessionId);

      DMLTransactionPlan transactionPlan = WaspParser.generateTransactionPlan(context, dmlPlans);
      final long afterGenPlan = EnvironmentEdgeManager.currentTimeMillis();
      ((FServer) this.service).getMetrics().updateGenPlan(
          afterGenPlan - beforeGenPlan);
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.plan.parser.ParseContext

Copyright © 2018 www.massapicom. 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.