.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.");
}
}
}
SQLPartitioningClause partitioning = waspSqlCreateTableStatement
.getPartitioning();
byte[][] splitKeys = null;
if (partitioning != null) {
if (table.isRootTable()) {
if (partitioning instanceof WaspSqlPartitionByKey) {
WaspSqlPartitionByKey partitionKey = (WaspSqlPartitionByKey) partitioning;
byte[] start = convert(null, partitionKey.getStart());
byte[] end = convert(null, partitionKey.getEnd());
int partitionCount = convertToInt(partitionKey.getPartitionCount());
splitKeys = Bytes.split(start, end, partitionCount - 3);
} else {
throw new UnsupportedException("Unsupported SQLPartitioningClause "
+ partitioning);
}
} else {
throw new UnsupportedException(
"Partition by only supported for Root Table");
}
}
CreateTablePlan createTable = new CreateTablePlan(table, splitKeys);
context.setPlan(createTable);