/** * @param c Column to take type definition from. * @return Type. */ public static GridSqlType fromColumn(Column c) { if (c.getName() != null) c = new Column(null, c.getType(), c.getPrecision(), c.getScale(), c.getDisplaySize()); return new GridSqlType(c.getType(), c.getScale(), c.getPrecision(), c.getDisplaySize(), c.getCreateSQL()); }
/** * @param data Data. */ public GridH2MetaTable(CreateTableData data) { super(data); ArrayList<Column> cols = data.columns; assert cols.size() == 4 : cols; Column id = cols.get(ID); assert "ID".equals(id.getName()) && id.getType() == Value.INT : cols; assert id.getColumnId() == ID; index = new MetaIndex(); }
/** * For the given list of columns, disable "nullable" for those columns that * are primary key columns. * * @param columns the list of columns */ protected void changePrimaryKeysToNotNull(ArrayList<Column> columns) { if (pkColumns != null) { for (Column c : columns) { for (IndexColumn idxCol : pkColumns) { if (c.getName().equals(idxCol.columnName)) { c.setNullable(false); } } } } }
public void setDataType(Column col) { dataType = col.getType(); precision = col.getPrecision(); displaySize = col.getDisplaySize(); scale = col.getScale(); }
if (userDataType != null) { templateColumn = userDataType.getColumn(); dataType = DataType.getDataType(templateColumn.getType()); comment = templateColumn.getComment(); original = templateColumn.getOriginalSQL(); precision = templateColumn.getPrecision(); displaySize = templateColumn.getDisplaySize(); scale = templateColumn.getScale(); enumerators = templateColumn.getEnumerators(); } else { Mode mode = database.getMode(); Column column = new Column(columnName, type, precision, scale, displaySize, enumerators); if (templateColumn != null) { column.setNullable(templateColumn.isNullable()); column.setDefaultExpression(session, templateColumn.getDefaultExpression()); int selectivity = templateColumn.getSelectivity(); if (selectivity != Constants.SELECTIVITY_DEFAULT) { column.setSelectivity(selectivity); Expression checkConstraint = templateColumn.getCheckConstraint( session, columnName); column.addCheckConstraint(session, checkConstraint); column.setComment(comment); column.setOriginalSQL(original); return column;
table.lock(session, true, true); if (newColumn != null) { checkDefaultReferencesTable(table, newColumn.getDefaultExpression()); checkClustering(newColumn); checkDefaultReferencesTable(table, column.getDefaultExpression()); checkClustering(column); if (!oldColumn.isNullable()) { oldColumn.setNullable(false); db.updateMeta(session, table); break; if (oldColumn.isNullable()) { oldColumn.setNullable(true); db.updateMeta(session, table); break; Sequence sequence = oldColumn == null ? null : oldColumn.getSequence(); checkDefaultReferencesTable(table, defaultExpression); oldColumn.setSequence(null); oldColumn.setDefaultExpression(session, defaultExpression); removeSequence(table, sequence); db.updateMeta(session, table); oldColumn.setOnUpdateExpression(session, defaultExpression); db.updateMeta(session, table);
column = new Column(columnName, Value.LONG); column.setOriginalSQL("IDENTITY"); parseAutoIncrement(column); column.setPrimaryKey(true); column = new Column(columnName, Value.INT); column.setOriginalSQL("SERIAL"); parseAutoIncrement(column); column.setPrimaryKey(true); column.setVisible(false); } else if (readIf("VISIBLE")) { column.setVisible(true); column.setNullable(true); break; case NULL_IS_NOT_ALLOWED: column.setNullable(false); break; case NO_NULL_CONSTRAINT_FOUND: column.setNullable(defaultNullable & column.isNullable()); break; default: column.setComputedExpression(expr); } else if (readIf("DEFAULT")) {
int type = Value.UNKNOWN; if (columnTemplates != null && columnTemplates.length > i) { name = columnTemplates[i].getName(); type = columnTemplates[i].getType(); int scale = expr.getScale(); int displaySize = expr.getDisplaySize(); Column col = new Column(name, type, precision, scale, displaySize); col.setTable(this, i); .getCheckConstraint(session, name); if (checkExpression != null) { col.addCheckConstraint(session, checkExpression); cols = new Column[columnTemplates.length]; for (int i = 0; i < columnTemplates.length; i++) { cols[i] = columnTemplates[i].getClone();
private Table cloneTableStructure(Table table, Column[] columns, Database db, String tempName, ArrayList<Column> newColumns) { for (Column col : columns) { newColumns.add(col.getClone()); Column foundCol = null; for (Column newCol : newColumns) { if (newCol.getName().equals(removeCol.getName())) { foundCol = newCol; break; throw DbException.throwInternalError(removeCol.getCreateSQL()); position = 0; } else if (addBefore != null) { position = table.getColumn(addBefore).getColumnId(); } else if (addAfter != null) { position = table.getColumn(addAfter).getColumnId() + 1; } else { position = columns.length; int position = oldColumn.getColumnId(); newColumns.set(position, newColumn); Expression def = nc.getDefaultExpression(); columnList.append(def == null ? "NULL" : def.getSQL()); } else { columnList.append(nc.getSQL()); Sequence seq = col.getSequence();
if (col.isAutoIncrement()) throw new IgniteSQLException("AUTO_INCREMENT columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION); throw new IgniteSQLException("Computed columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION); if (col.getDefaultExpression() != null) { if (!col.getDefaultExpression().isConstant()) { throw new IgniteSQLException("Non-constant DEFAULT expressions are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION); DataType colType = DataType.getDataType(col.getType()); DataType dfltType = DataType.getDataType(col.getDefaultExpression().getType()); throw new IgniteSQLException("Invalid default value for column. [colName=" + col.getName() + ", colType=" + colType.name + ", dfltValueType=" + dfltType.name + ']', if (col.getSequence() != null) throw new IgniteSQLException("SEQUENCE columns are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION); if (col.getSelectivity() != Constants.SELECTIVITY_DEFAULT) throw new IgniteSQLException("SELECTIVITY column attribute is not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION); throw new IgniteSQLException("Column CHECK constraints are not supported [colName=" + col.getName() + ']', IgniteQueryErrorCode.UNSUPPORTED_OPERATION);
String columnName = readColumnIdentifier(); Column column = parseColumnForTable(columnName, true); if (column.isAutoIncrement() && column.isPrimaryKey()) { column.setPrimaryKey(false); IndexColumn[] cols = { new IndexColumn() }; cols[0].columnName = column.getName(); AlterTableAddConstraint pk = new AlterTableAddConstraint( session, schema, false); boolean hash = readIf("HASH"); IndexColumn[] cols = { new IndexColumn() }; cols[0].columnName = column.getName(); AlterTableAddConstraint pk = new AlterTableAddConstraint( session, schema, false); read("KEY"); IndexColumn[] cols = { new IndexColumn() }; cols[0].columnName = column.getName(); CreateIndex idx = createAffinityIndex(schema, tableName, cols); command.addConstraintCommand(idx); column.setNullable(false); column.addCheckConstraint(session, expr);
protected void setColumns(Column[] columns) { this.columns = columns; if (columnMap.size() > 0) { columnMap.clear(); } for (int i = 0; i < columns.length; i++) { Column col = columns[i]; int dataType = col.getType(); if (dataType == Value.UNKNOWN) { throw DbException.get( ErrorCode.UNKNOWN_DATA_TYPE_1, col.getSQL()); } col.setTable(this, i); String columnName = col.getName(); if (columnMap.get(columnName) != null) { throw DbException.get( ErrorCode.DUPLICATE_COLUMN_NAME_1, columnName); } columnMap.put(columnName, col); } }
/** * Constructs non-nullable column. * * @param name Column name. * @param type Column data type. * @return {@link GridSqlColumn} with given name and type. */ private static GridSqlColumn cn(String name, int type) { Column col = new Column(name, type); col.setNullable(false); return new GridSqlColumn(col, null, name); }
@Override protected void feedCreateTableData(SHPDriver driver, CreateTableData data) throws IOException { Column geometryColumn = new Column("THE_GEOM", Value.GEOMETRY); Parser parser = new Parser(data.session); geometryColumn.addCheckConstraint(data.session, parser.parseExpression("ST_GeometryTypeCode(THE_GEOM) = "+getGeometryTypeCodeFromShapeType(driver.getShapeFileHeader().getShapeType()))); data.columns.add(geometryColumn); DBFEngine.feedTableDataFromHeader(driver.getDbaseFileHeader(), data); } }
@Override public String getColumnName() { return columnName != null ? columnName : column.getName(); }
@Override public Expression optimize(ExpressionColumn expressionColumn, Column column) { return expressions[column.getColumnId()]; }
for (IndexColumn c : cols) { Column column = c.column; if (column.isNullable()) { throw DbException.get( ErrorCode.COLUMN_MUST_NOT_BE_NULLABLE_1, column.getName()); column.setPrimaryKey(true);
Column col = new Column("C" + i, Value.INT); data.columns.add(col); Column[] tableColumns = table.getColumns(); for (IndexColumn indexColumn : cols) { tableColumns[indexColumn.column.getColumnId()].setNullable(false);