/** * @param name Name. * @param type Type. */ protected static Column newColumn(String name, int type) { return new Column(name, type); }
/** * @return Columns. */ private static ArrayList<Column> planColumns() { ArrayList<Column> res = new ArrayList<>(1); res.add(new Column("PLAN", Value.STRING)); return res; }
public Column getClone() { Column newColumn = new Column(name, type, precision, scale, displaySize, enumerators); newColumn.copy(this); return newColumn; }
@Override public Column getRowIdColumn() { if (rowIdColumn == null) { rowIdColumn = new Column(Column.ROWID, Value.LONG); rowIdColumn.setTable(this, -1); } return rowIdColumn; }
@Override public Column getRowIdColumn() { if (rowIdColumn == null) { rowIdColumn = new Column(Column.ROWID, Value.LONG); rowIdColumn.setTable(this, -1); } return rowIdColumn; }
/** * Create a new range with the given start and end expressions. * * @param schema the schema (always the main schema) * @param min the start expression * @param max the end expression * @param noColumns whether this table has no columns */ public RangeTable(Schema schema, Expression min, Expression max, boolean noColumns) { super(schema, 0, NAME, true, true); Column[] cols = noColumns ? new Column[0] : new Column[] { new Column( "X", Value.LONG) }; this.min = min; this.max = max; setColumns(cols); }
private void openMetaIndex() { CreateTableData data = new CreateTableData(); ArrayList<Column> cols = data.columns; cols.add(new Column("ID", Value.INT)); cols.add(new Column("TYPE", Value.INT)); cols.add(new Column("PARENT", Value.INT)); cols.add(new Column("HEAD", Value.INT)); cols.add(new Column("OPTIONS", Value.STRING)); cols.add(new Column("COLUMNS", Value.STRING)); metaSchema = new Schema(database, 0, "", null, true); data.schema = metaSchema; data.tableName = "PAGE_INDEX"; data.id = META_TABLE_ID; data.temporary = false; data.persistData = true; data.persistIndexes = true; data.create = false; data.session = pageStoreSession; metaTable = new RegularTable(data); metaIndex = (PageDataIndex) metaTable.getScanIndex( pageStoreSession); metaObjects.clear(); metaObjects.put(-1, metaIndex); }
private LocalResult createResult() { Expression[] expressions = { new ExpressionColumn( session.getDatabase(), new Column("SCRIPT", Value.STRING)) }; return new LocalResult(session, expressions, 1); }
/** * @param name Column name. * @param type Column data type. * @return {@link GridSqlColumn} with given name and type. */ private static GridSqlColumn c(String name, int type) { return new GridSqlColumn(new Column(name, type), null, name); }
/** * Get the system columns that this table understands. This is used for * compatibility with other databases. The columns are only returned if the * current mode supports system columns. * * @return the system columns */ @Override public Column[] getSystemColumns() { if (!session.getDatabase().getMode().systemColumns) { return null; } Column[] sys = new Column[3]; sys[0] = new Column("oid", Value.INT); sys[0].setTable(table, 0); sys[1] = new Column("ctid", Value.STRING); sys[1].setTable(table, 0); sys[2] = new Column("CTID", Value.STRING); sys[2].setTable(table, 0); return sys; }
private Column[] createColumns(String... names) { Column[] cols = new Column[names.length]; for (int i = 0; i < names.length; i++) { String nameType = names[i]; int idx = nameType.indexOf(' '); int dataType; String name; if (idx < 0) { dataType = database.getMode().lowerCaseIdentifiers ? Value.STRING_IGNORECASE : Value.STRING; name = nameType; } else { dataType = DataType.getTypeByName(nameType.substring(idx + 1), database.getMode()).type; name = nameType.substring(0, idx); } cols[i] = new Column(name, dataType); } return cols; }
/** * Extracts expression columns from the given result set. * * @param session the session * @param rs the result set * @return an array of expression columns */ public static Expression[] getExpressionColumns(Session session, ResultSet rs) { try { ResultSetMetaData meta = rs.getMetaData(); int columnCount = meta.getColumnCount(); Expression[] expressions = new Expression[columnCount]; Database db = session == null ? null : session.getDatabase(); for (int i = 0; i < columnCount; i++) { String name = meta.getColumnLabel(i + 1); int type = DataType.getValueTypeFromResultSet(meta, i + 1); int precision = meta.getPrecision(i + 1); int scale = meta.getScale(i + 1); int displaySize = meta.getColumnDisplaySize(i + 1); Column col = new Column(name, type, precision, scale, displaySize); Expression expr = new ExpressionColumn(db, col); expressions[i] = expr; } return expressions; } catch (SQLException e) { throw DbException.convert(e); } }
/** * 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 public Expression[] getExpressionColumns(Session session) { ExpressionColumn[] expr = new ExpressionColumn[list.length]; for (int i = 0; i < list.length; i++) { Expression e = list[i]; Column col = new Column("C" + (i + 1), e.getType(), e.getPrecision(), e.getScale(), e.getDisplaySize()); expr[i] = new ExpressionColumn(session.getDatabase(), col); } return expr; }
SelectListColumnResolver(Select select) { this.select = select; int columnCount = select.getColumnCount(); columns = new Column[columnCount]; expressions = new Expression[columnCount]; ArrayList<Expression> columnList = select.getExpressions(); ColumnNamer columnNamer= new ColumnNamer(select.getSession()); for (int i = 0; i < columnCount; i++) { Expression expr = columnList.get(i); String columnName = columnNamer.getColumnName(expr, i, expr.getAlias()); Column column = new Column(columnName, Value.NULL); column.setTable(null, i); columns[i] = column; expressions[i] = expr.getNonAliasExpression(); } }
/** * @param e Expression to take type from. * @return Type. */ public static GridSqlType fromExpression(Expression e) { if (e.getType() == Value.UNKNOWN) return UNKNOWN; return fromColumn(new Column(null, e.getType(), e.getPrecision(), e.getScale(), e.getDisplaySize())); }
for (int i = 0; i < expressions.length; i++) { int type = expressions[i].getType(); Column col = new Column(COLUMN_NAME + i, type); if (type == Value.CLOB || type == Value.BLOB) {
/** * Extracts expression columns from ValueArray * * @param session the current session * @param value the value to extract columns from * @return array of expression columns */ static Expression[] getExpressionColumns(Session session, ValueArray value) { Value[] list = value.getList(); ExpressionColumn[] expr = new ExpressionColumn[list.length]; for (int i = 0, len = list.length; i < len; i++) { Value v = list[i]; Column col = new Column("C" + (i + 1), v.getType(), v.getPrecision(), v.getScale(), v.getDisplaySize()); expr[i] = new ExpressionColumn(session.getDatabase(), col); } return expr; }
/** * @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()); }
private Expression readConcat() { Expression r = readSum(); while (true) { if (readIf("||")) { r = new Operation(OpType.CONCAT, r, readSum()); } else if (readIf("~")) { if (readIf("*")) { Function function = Function.getFunction(database, "CAST"); function.setDataType(new Column("X", Value.STRING_IGNORECASE)); function.setParameter(0, r); r = function; } r = new CompareLike(database, r, readSum(), null, true); } else if (readIf("!~")) { if (readIf("*")) { Function function = Function.getFunction(database, "CAST"); function.setDataType(new Column("X", Value.STRING_IGNORECASE)); function.setParameter(0, r); r = function; } r = new ConditionNot(new CompareLike(database, r, readSum(), null, true)); } else { return r; } } }