Package com.alibaba.wasp.meta

Examples of com.alibaba.wasp.meta.Field


        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);
View Full Code Here


    // table columns.
    List<SQLTableElement> tableElementList = waspSqlCreateTableStatement
        .getTableElementList(); // columns info
    LinkedHashMap<String, Field> columns = new LinkedHashMap<String, Field>();
    for (SQLTableElement element : tableElementList) {
      Field field = parse(element);
      columns.put(field.getName(), field);
    }
    // Check if columns are legal.
    metaEventOperation.areLegalTableColumns(null, columns.values());
    checkFamilyLegal(columns.values(), metaEventOperation);

    // Primary keys check will be done in this following method
    LinkedHashMap<String, Field> primaryKeys = parse(primaryKeysSQLExpr,
        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);
View Full Code Here

      LinkedHashMap<String, Field> columns) throws UnsupportedException {
    LinkedHashMap<String, Field> particularFields = new LinkedHashMap<String, Field>(
        particularColumns.size());
    for (SQLExpr expr : particularColumns) {
      String name = parseName(expr);
      Field field = columns.get(name);
      if (field == null) {
        throw new UnsupportedException(
            "Unsupported table don't have this primaryKey " + expr);
      }
      particularFields.put(name, field);
View Full Code Here

    }
    return particularFields;
  }

  private Field parse(SQLTableElement tableElement) throws UnsupportedException {
    Field field = null;
    FieldKeyWord keyWord = null;
    if (tableElement instanceof WaspSqlColumnDefinition) {
      WaspSqlColumnDefinition column = (WaspSqlColumnDefinition) tableElement;
      if (column.getColumnConstraint() == FieldKeyWord.REQUIRED) {
        keyWord = FieldKeyWord.REQUIRED;
      } else if (column.getColumnConstraint() == FieldKeyWord.OPTIONAL) {
        keyWord = FieldKeyWord.OPTIONAL;
      } else if (column.getColumnConstraint() == FieldKeyWord.REPEATED) {
        keyWord = FieldKeyWord.REPEATED;
      } else {
        throw new UnsupportedException("Unsupported ColumnConstraint "
            + column.getColumnConstraint());
      }
      SQLName name = column.getName();
      SQLDataType dataType = column.getDataType();
      SQLName columnFamilyName = column.getColumnFamily();
      String columnFamily = FConstants.COLUMNFAMILYNAME_STR;
      if (columnFamilyName != null) {
        columnFamily = parseName(columnFamilyName);
      }
      field = new Field(keyWord, columnFamily, parseName(name),
          parse(dataType), column.getComment());
      return field;
    } else {
      throw new UnsupportedException("Unsupported SQLColumnDefinition "
          + tableElement);
View Full Code Here

  public int getIndex(String name, LinkedHashMap<String, Field> columns)
      throws UnsupportedException {
    Iterator<Entry<String, Field>> iter = columns.entrySet().iterator();
    int i = 0;
    while (iter.hasNext()) {
      Field field = iter.next().getValue();
      if (field.getName().equals(name)) {
        return i;
      }
      i++;
    }
    throw new UnsupportedException(name + " is not in set");
View Full Code Here

    return addFields;
  }

  private static Field convertColumnDefForAlterTable(SQLColumnDefinition column)
      throws UnsupportedException {
    Field field = new Field();
    if (column instanceof WaspSqlColumnDefinition) {
      WaspSqlColumnDefinition waspColumn = (WaspSqlColumnDefinition) column;
      if (waspColumn.getComment() != null) {
        field.setComment(waspColumn.getComment());
      }
      if (waspColumn.getColumnFamily() != null) {
        field.setFamily(parseName(waspColumn.getColumnFamily()));
      } else {
        field.setFamily(FConstants.COLUMNFAMILYNAME_STR);
      }
      field.setKeyWord(FieldKeyWord.OPTIONAL);
      field.setName(parseName(column.getName()));
      field.setType(parse(column.getDataType()));
    } else {
      field.setComment(column.getComment());
      field.setFamily(FConstants.COLUMNFAMILYNAME_STR);
      field.setKeyWord(FieldKeyWord.OPTIONAL);
      field.setName(parseName(column.getName()));
      field.setType(parse(column.getDataType()));
    }
    return field;
  }
View Full Code Here

    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
View Full Code Here

    Iterator<String> iter = columns.iterator();
    int i = 0;
    while (iter.hasNext()) {
      String columnName = iter.next();
      // Get the column's info
      Field column = metaEventOperation.getColumnInfo(table, columnName);
      byte[] value = convert(column, exprValues.get(i));
      Iterator<Entry<String, Field>> pkIter = table.getPrimaryKeys().entrySet()
          .iterator();
      int j = 0;
      while (pkIter.hasNext()) {
        if (pkIter.next().getKey().equalsIgnoreCase(columnName)) {
          array[j] = new Pair<String, byte[]>(columnName, value);
          break;
        }
        j++;
      }
      // Check the input is the same as DataType
      checkType(column, exprValues.get(i));
      ColumnStruct columnAction = new ColumnStruct(table.getTableName(),
          column.getFamily(), columnName, column.getType(), value);
      cols.add(columnAction);
      i++;
    }

    return new Pair<List<Pair<String, byte[]>>, List<ColumnStruct>>(
View Full Code Here

  private List<ColumnStruct> buildColumnsNotInIndex(FTable table, Index index, QueryInfo queryInfo) throws UnsupportedException {
    List<ColumnStruct> columns = new ArrayList<ColumnStruct>();
    LinkedHashMap<String, Field> fields = table.getColumns();
    for (String fieldname : queryInfo.getAllConditionFieldName()) {
      if(!index.getIndexKeys().containsKey(fieldname)) {
        Field field = fields.get(fieldname);
        if(field != null) {
          ColumnStruct column = buildColumnStruct(table, queryInfo, field);
          columns.add(column);
        }
      }
View Full Code Here

  private List<ColumnStruct> buildAllConditionColumns(FTable table, QueryInfo queryInfo) throws UnsupportedException {
    List<ColumnStruct> columns = new ArrayList<ColumnStruct>();
    LinkedHashMap<String, Field> fields = table.getColumns();
    for (String fieldname : queryInfo.getAllConditionFieldName()) {
      Field field = fields.get(fieldname);
      if(field != null) {
        ColumnStruct column = buildColumnStruct(table, queryInfo, field);
        columns.add(column);
      }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.meta.Field

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.