Examples of FTable


Examples of com.alibaba.wasp.meta.FTable

      MySqlAlterTableStatement sqlAlterTableStatement,
      MetaEventOperation metaEventOperation) throws IOException {
    SQLExprTableSource tableSource = sqlAlterTableStatement.getTableSource();
    String tableName = parseFromClause(tableSource);
    // check if table exists and get Table info
    FTable oldTable = metaEventOperation.checkAndGetTable(tableName, true);

    FTable newTable = FTable.clone(oldTable);

    List<SQLAlterTableItem> items = sqlAlterTableStatement.getItems();
    for (SQLAlterTableItem item : items) {
      if (item instanceof WaspSqlAlterTableChangeColumn) {
        // Alter Table Change Column
        WaspSqlAlterTableChangeColumn changeColumn = (WaspSqlAlterTableChangeColumn) item;

        SQLName columnName = changeColumn.getColumnName();
        LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();
        String oldColumnName = parseName(columnName);
        // Table have this column and this column is not primary key
        metaEventOperation.checkFieldExists(oldTable, oldColumnName);
        metaEventOperation.checkFieldNotInPrimaryKeys(oldTable, oldColumnName);
        // Check column not in a index
        metaEventOperation.checkColumnNotInIndex(oldTable, oldColumnName);

        // Which column(index) to change
        Field field = ftableColumns.get(oldColumnName); // Change this Field
        SQLColumnDefinition newColumnDefinition = changeColumn
            .getNewColumnDefinition();
        // ColumnFamily specify do not supported.
        if (newColumnDefinition instanceof WaspSqlColumnDefinition) {
          WaspSqlColumnDefinition waspSqlColumnDefinition =
              (WaspSqlColumnDefinition) newColumnDefinition;
          if (waspSqlColumnDefinition.getColumnFamily() != null) {
            throw new UnsupportedException("Alter Table, columnFamily specify do not supported.");
          }
        }
        if (newColumnDefinition.getDataType() != null) {
          field.setType(parse(newColumnDefinition.getDataType()));
        }
        String newColumnName = parseName(newColumnDefinition.getName());
        if (!oldColumnName.equals(newColumnName)) { // Change column name
          for (Field f : ftableColumns.values()) {
            if (f.getName().equalsIgnoreCase(newColumnName)) {
              throw new UnsupportedException(
                  "Unsupported. Rename one column to a column that already column "
                      + newColumnName);
            }
          }
          field.setName(newColumnName);
        }
      } else if (item instanceof MySqlAlterTableAddColumn) {
        // Alter Table Add Column
        MySqlAlterTableAddColumn addColumn = (MySqlAlterTableAddColumn) item;
        List<SQLColumnDefinition> columns = addColumn.getColumns();
        boolean first = addColumn.isFirst();
        SQLName afterColumn = addColumn.getAfterColumn();
        LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();

        List<Field> addFields = convertColumnDefForAlterTable(columns);
        // check Duplicate column name
        metaEventOperation.areLegalTableColumns(ftableColumns.values(),
            addFields);
        // Do not support add ColumnFamily dynamic right now.
        metaEventOperation.checkColumnFamilyName(ftableColumns.values(), addFields);
        if (first) {
          this.addFieldByPosition(-1, addFields, ftableColumns, newTable);
        } else if (afterColumn != null) {
          int index = getIndex(parseName(afterColumn), ftableColumns);
          this.addFieldByPosition(index, addFields, ftableColumns, newTable);
        } else {
          int index = ftableColumns.size() - 1;
          this.addFieldByPosition(index, addFields, ftableColumns, newTable);
        }
      } else if (item instanceof SQLAlterTableDropColumnItem) {
        // Alter Table Drop Column
        SQLAlterTableDropColumnItem dropColumn = (SQLAlterTableDropColumnItem) item;
        SQLName columnName = dropColumn.getColumnName();
        String cname = parseName(columnName);
        // This column is not primary key
        metaEventOperation.checkFieldNotInPrimaryKeys(oldTable, cname);
        // Check column not in a index, if you want to drop the column you
        // should drop the index first
        metaEventOperation.checkColumnNotInIndex(oldTable, cname);

        LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();
        Field field = ftableColumns.remove(cname);
        if (field == null) {
          throw new UnsupportedException("Unsupported Do not find this column "
              +  SQLUtils.toSQLString(((SQLAlterTableDropColumnItem) item).getColumnName()));
        }
        newTable.setColumns(ftableColumns);
      } else {
        throw new UnsupportedException(SQLUtils.toSQLString(item) + " SQLAlterTableItem Unsupported");
      }
    }
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

        columns);

    long createTime = System.currentTimeMillis();
    long lastAccessTime = createTime;
    String owner = "me";
    FTable table = new FTable(null, tableName, tableType, owner, createTime,
        lastAccessTime, columns, primaryKeys, primaryKeys.entrySet().iterator()
            .next().getValue());
    SQLExpr entityGroupKeySQLExpr = waspSqlCreateTableStatement
        .getEntityGroupKey();
    Field entityGroupKey = primaryKeys.get(parseName(entityGroupKeySQLExpr));
    if (entityGroupKey == null) {
      throw new UnsupportedException(entityGroupKeySQLExpr
          + " is ForeignKey, but don't in primaryKeys.");
    }
    table.setEntityGroupKey(entityGroupKey);

    if (tableType == FTable.TableType.CHILD) {
      String parentName = parseFromClause(waspSqlCreateTableStatement
          .getInTableName());
      table.setParentName(parentName);
      if (!parentName.equals(parseFromClause(waspSqlCreateTableStatement
          .getReferenceTable()))) {
        throw new UnsupportedException(" in table "
            + waspSqlCreateTableStatement.getInTableName()
            + " != references table "
            + waspSqlCreateTableStatement.getReferenceTable());
      }

      // Check parent's EGK equals child's EGK.
      TableSchemaCacheReader reader = TableSchemaCacheReader
          .getInstance(configuration);
      FTable parentTable = reader.getSchema(parentName);
      if (parentTable == null) {
        parentTable = TableSchemaCacheReader.getService(reader.getConf())
            .getTable(tableName);
      }
      if (parentTable == null) {
        throw new TableNotFoundException("Not found parent table:" + parentName);
      }

      if (!parentTable.getEntityGroupKey().getName()
          .equals(table.getEntityGroupKey().getName())) {
        throw new UnsupportedException("Parent" + parentName
            + "'s egk doesn't equals Child" + tableName + "'s egk.");
      }

      // Check child's PKS contains parent's PKS.
      for (Field parentPrimaryKey : parentTable.getPrimaryKeys().values()) {
        boolean found = table.getPrimaryKeys().containsKey(
            parentPrimaryKey.getName());
        if (!found) {
          throw new UnsupportedException(
              "Child's pks must contains parent's pks.");
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

    SQLExpr indexNameExpr = sqlDropIndexStatement.getIndexName();
    SQLExpr table = sqlDropIndexStatement.getTableName();
    String tableName = parseName(table);

    // check if table exists and get Table info
    FTable ftable = metaEventOperation.checkAndGetTable(tableName, true);

    String indexName = parseName(indexNameExpr);
    metaEventOperation.checkIndexExists(ftable, indexName);

    DropIndexPlan dropIndex = new DropIndexPlan(indexName, tableName);
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

    SQLName table = sqlCreateIndexStatement.getTable();
    String tableName = parseName(table);
    LOG.debug("Create Index SQL TableName " + table);

    // check if table exists and get Table info
    FTable fTable = metaEventOperation.checkAndGetTable(tableName, true);

    // check the index not exists
    metaEventOperation.checkIndexNotExists(fTable, indexName);

    // Field
    List<SQLSelectOrderByItem> items = sqlCreateIndexStatement.getItems();
    LinkedHashSet<String> columns = new LinkedHashSet<String>(items.size());
    List<String> desc = new ArrayList<String>();
    for (SQLSelectOrderByItem item : items) {
      String columnName = parseName(item.getExpr());
      if (columns.contains(columnName)) {
        throw new UnsupportedException("Index have two same field '" + columnName + "'");
      } else {
        columns.add(columnName);
      }
      if (item.getType() == SQLOrderingSpecification.DESC) {
        desc.add(columnName);
      }
    }

    if (!metaEventOperation.isLegalDescFields(fTable, desc)) {
      throw new UnsupportedException(
          "Currently we only support the ascending and descending time field.");
    }

    List<String> colList = new ArrayList<String>();
    colList.addAll(columns);
    if (metaEventOperation.arePrimaryKeys(fTable, colList)) {
      throw new UnsupportedException("Index keys is Primary Keys.");
    }
    if (metaEventOperation.containPrimaryKeys(fTable, colList)) {
      throw new UnsupportedException("Index keys contain all Primary Keys.");
    }

    LinkedHashMap<String, Field> indexKeys = metaEventOperation
        .checkAndGetFields(fTable, columns);
    // Check the indexKeys whether have Duplicate column name
    metaEventOperation.areLegalTableColumns(null, indexKeys.values());

    Index index = new Index(indexName, tableName, indexKeys);
    // Check if two index have the same columns and the same columns order
    metaEventOperation.checkTwoIndexWithSameColumn(fTable, index);

    index.setDesc(desc);
    index.setStoring(parse(sqlCreateIndexStatement.getStoringCols(),
        fTable.getColumns()));
    CreateIndexPlan createIndexPlan = new CreateIndexPlan(index);

    context.setPlan(createIndexPlan);
    LOG.debug("CreateIndexPlan " + createIndexPlan.toString());
  }
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

  private static String checkTablesAndGetParent(Set<String> checkTables, ParseContext context) throws MetaException, TransactionParseException {
    TableSchemaCacheReader reader = context.getTsr();
    String parentTable = null;
    for (String checkTable : checkTables) {
      FTable table = reader.getSchema(checkTable);
      if(table.getTableType() == FTable.TableType.ROOT) {
        if(parentTable != null && !parentTable.equals(table.getTableName())) {
          throw new TransactionParseException("in a transaction can be no more than one parent table");
        } else {
          parentTable = table.getTableName();
        }
      } else {
        if(parentTable != null && (!parentTable.equals(table.getParentName()))) {
          throw new TransactionParseException("in a transaction can be no more than one parent table. and others must be the parent's child");
        } else {
          parentTable = table.getParentName();
        }
      }

    }
    return parentTable;
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

    // Parse The FROM clause
    String fTableName = parseFromClause(sqlInsertStatement.getTableSource());
    LOG.debug("INSERT SQL TableSource " + sqlInsertStatement.getTableSource());
    LOG.debug("From table " + fTableName);
    // check if table exists and get Table info
    FTable table = metaEventOperation.checkAndGetTable(fTableName, false);

    // Parse The columns
    LinkedHashSet<String> insertColumns = parseInsertColumns(sqlInsertStatement
        .getColumns());
    LOG.debug("INSERT SQL Insert columns " + sqlInsertStatement.getColumns());
    // check if table has this columns
    metaEventOperation.checkAndGetFields(table, insertColumns);
    metaEventOperation.checkRequiredFields(table, insertColumns);

    // Before insert a row , it should not be exists, we do not check exists
    // here but check it in execution.
    List<InsertAction> actions = new ArrayList<InsertAction>();
    if (sqlInsertStatement instanceof WaspSqlInsertStatement) {
      // For MySQL, INSERT statements that use VALUES syntax can insert multiple
      // rows. see http://dev.mysql.com/doc/refman/5.5/en/insert.html
      List<ValuesClause> valuesList = ((WaspSqlInsertStatement) sqlInsertStatement)
          .getValuesList();
      if (valuesList.size() > 1) {
        throw new UnsupportedException("Insert multi value unsupported now");
      }
      LOG.debug("INSERT SQL Insert Values List " + valuesList);
      for (ValuesClause values : valuesList) {
        actions.add(genInsertAction(metaEventOperation, table, insertColumns,
            values));
      }
    } else if (sqlInsertStatement instanceof SQLInsertStatement) {
      // INSERT statements that use VALUES syntax insert one row
      ValuesClause values = sqlInsertStatement.getValues();
      LOG.debug("INSERT SQL Insert Values " + values);
      actions.add(genInsertAction(metaEventOperation, table, insertColumns,
          values));
    }

    if (context.isGenWholePlan()) {
      for (InsertAction insertAction : actions) {
        // Get entityGroupLocation according to entity group key
        EntityGroupLocation entityGroupLocation = this.connection
            .locateEntityGroup(Bytes.toBytes(table.getTableName()),
                insertAction.getValueOfEntityGroupKey());
        insertAction.setEntityGroupLocation(entityGroupLocation);
      }
    }
    InsertPlan insertPlan = new InsertPlan(actions);
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

    // Parse The FROM clause
    String wtableName = parseFromClause(sqlDeleteStatement.getTableSource());
    LOG.debug("UPDATE SQL From clause " + sqlDeleteStatement.getTableSource());
    // check if table exists and get Table info
    FTable table = metaEventOperation.checkAndGetTable(wtableName, false);

    // Parse The WHERE clause
    SQLExpr where = sqlDeleteStatement.getWhere();
    LOG.debug("UPDATE SQL where " + where);
    LinkedHashMap<String, Condition> eqConditions = new LinkedHashMap<String, Condition>();
    LinkedHashMap<String, Condition> ranges = new LinkedHashMap<String, Condition>();
    ParserUtils.parse(where, eqConditions, ranges);
    if (ranges.size() > 0) {
      throw new UnsupportedException("RANGE is not supported!");
    }

    // check if table has this columns
    metaEventOperation.checkAndGetFields(table, eqConditions.keySet());

    List<Pair<String, byte[]>> primaryKeyPairs = metaEventOperation
        .getPrimaryKeyPairList(table, eqConditions, null);
    if (primaryKeyPairs == null) {
      throw new NotMatchPrimaryKeyException("Not match primary key.");
    }

    byte[] primayKey = RowBuilder.build().genRowkey(primaryKeyPairs);
    DeleteAction action = new DeleteAction(wtableName, primayKey);
    if (context.isGenWholePlan()) {
      Condition entityGroupKeyCondition = ParserUtils.getCondition(table
          .getEntityGroupKey().getName(), eqConditions);
      // Get entityGroupLocation according to entity group key
      EntityGroupLocation entityGroupLocation = this.connection
          .locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
              .convert(table.getColumn(entityGroupKeyCondition.getFieldName()),
                  entityGroupKeyCondition.getValue()));
      action.setEntityGroupLocation(entityGroupLocation);
    }
    List<DeleteAction> actions = new ArrayList<DeleteAction>();
    actions.add(action);
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

    // Parse The FROM clause
    String fTableName = parseFromClause(sqlUpdateStatement.getTableSource());
    LOG.debug("UPDATE SQL From clause " + sqlUpdateStatement.getTableSource());
    // check if table exists and get Table info
    FTable table = metaEventOperation.checkAndGetTable(fTableName, false);

    // Parse The WHERE clause
    SQLExpr where = sqlUpdateStatement.getWhere();
    LOG.debug("UPDATE SQL where " + where);

    LinkedHashMap<String, Condition> conditions = new LinkedHashMap<String, Condition>();
    LinkedHashMap<String, Condition> ranges = new LinkedHashMap<String, Condition>();
    ParserUtils.parse(where, conditions, ranges);
    if (ranges.size() > 0) {
      throw new UnsupportedException(
          "RANGE is not supported by update operation!");
    }

    Set<String> conditionColumns = ParserUtils.getColumns(conditions);
    // check if table has this columns
    metaEventOperation.checkAndGetFields(table, conditionColumns);
    // check if where clause is primary keys
    metaEventOperation.checkIsPrimaryKey(table, conditionColumns);

    List<Pair<String, byte[]>> primaryKeyPairs = metaEventOperation
        .getPrimaryKeyPairList(table, conditions, null);
    if (primaryKeyPairs == null) {
      throw new IOException("Not match primary key.");
    }

    byte[] primayKey = RowBuilder.build().genRowkey(primaryKeyPairs);

    UpdateAction action = new UpdateAction(fTableName, primayKey);
    // Parse Update Item
    List<SQLUpdateSetItem> updateItems = sqlUpdateStatement.getItems();
    for (SQLUpdateSetItem updateItem : updateItems) {
      String columnName = parseColumn(updateItem.getColumn());
      // check this FTable has the column and not pk
      metaEventOperation.checkFieldNotInPrimaryKeys(table, columnName);
      Field field = table.getColumn(columnName);
      // Check the input is the same as DataType
      checkType(field, updateItem.getValue());
      byte[] value = convert(field, updateItem.getValue());
      String familyName = metaEventOperation.getColumnFamily(fTableName,
          columnName);
      action.addEntityColumn(fTableName, familyName, columnName,
          field.getType(), value);
    }
    if (context.isGenWholePlan()) {
      Condition entityGroupKeyCondition = ParserUtils.getCondition(table
          .getEntityGroupKey().getName(), conditions);
      // Get entityGroupLocation according to entity group key
      EntityGroupLocation entityGroupLocation = this.connection
          .locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
              .convert(table.getColumn(entityGroupKeyCondition.getFieldName()),
                  entityGroupKeyCondition.getValue()));
      action.setEntityGroupLocation(entityGroupLocation);
    }
    action.setSessionId(context.getSessionId());
    List<UpdateAction> actions = new ArrayList<UpdateAction>();
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

      // Parse The FROM clause
      String fTableName = parseFromClause(sqlSelectQueryBlock.getFrom());
      LOG.debug("SELECT SQL TableSource " + sqlSelectQueryBlock.getFrom());
      // check if table exists and get Table info(WTable)
      FTable table = metaEventOperation.checkAndGetTable(fTableName, false);

      LinkedHashSet<String> selectItem = null;
      AggregateInfo aggregateInfo = parseAggregateClause(sqlSelectQueryBlock.getSelectList(), table);
      if(aggregateInfo == null) {
        // Parse The SELECT clause
View Full Code Here

Examples of com.alibaba.wasp.meta.FTable

   * @throws java.io.IOException
   */
  @Override
  public FTable checkAndGetTable(String tableName, boolean fetch)
      throws IOException {
    FTable table = reader.getSchema(tableName);
    if (table == null) {
      if (fetch) {
        table = TableSchemaCacheReader.getService(reader.getConf()).getTable(
            tableName);
      }
View Full Code Here
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.