Пример #1
0
 ResultTempTable(Session session, Expression[] expressions, boolean distinct, SortOrder sort) {
   this.session = session;
   this.distinct = distinct;
   this.sort = sort;
   this.columnCount = expressions.length;
   Schema schema = session.getDatabase().getSchema(Constants.SCHEMA_MAIN);
   CreateTableData data = new CreateTableData();
   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) {
       containsLob = true;
     }
     data.columns.add(col);
   }
   data.id = session.getDatabase().allocateObjectId();
   data.tableName = "TEMP_RESULT_SET_" + data.id;
   data.temporary = true;
   data.persistIndexes = false;
   data.persistData = true;
   data.create = true;
   data.session = session;
   table = schema.createTable(data);
   if (sort != null || distinct) {
     createIndex();
   }
   parent = null;
 }
Пример #2
0
  /**
   * @param conn Connection.
   * @param qry Query.
   * @param explain Explain.
   * @return Table.
   * @throws IgniteCheckedException
   */
  private GridMergeTable createMergeTable(
      JdbcConnection conn, GridCacheSqlQuery qry, boolean explain) throws IgniteCheckedException {
    try {
      Session ses = (Session) conn.getSession();

      CreateTableData data = new CreateTableData();

      data.tableName = "T___";
      data.schema = ses.getDatabase().getSchema(ses.getCurrentSchemaName());
      data.create = true;

      if (!explain) {
        LinkedHashMap<String, ?> colsMap = qry.columns();

        assert colsMap != null;

        ArrayList<Column> cols = new ArrayList<>(colsMap.size());

        for (Map.Entry<String, ?> e : colsMap.entrySet()) {
          String alias = e.getKey();
          GridSqlType t = (GridSqlType) e.getValue();

          assert !F.isEmpty(alias);

          Column c = new Column(alias, t.type(), t.precision(), t.scale(), t.displaySize());

          cols.add(c);
        }

        data.columns = cols;
      } else data.columns = planColumns();

      return new GridMergeTable(data, ctx);
    } catch (Exception e) {
      U.closeQuiet(conn);

      throw new IgniteCheckedException(e);
    }
  }