/** @since 2.5 */
  public CsvSchema(
      Column[] columns,
      int features,
      char columnSeparator,
      int quoteChar,
      int escapeChar,
      char[] lineSeparator,
      int arrayElementSeparator,
      char[] nullValue) {
    if (columns == null) {
      columns = NO_COLUMNS;
    } else {
      columns = _link(columns);
    }
    _columns = columns;
    _features = features;
    _columnSeparator = columnSeparator;
    _arrayElementSeparator = arrayElementSeparator;
    _quoteChar = quoteChar;
    _escapeChar = escapeChar;
    _lineSeparator = lineSeparator;
    _nullValue = nullValue;

    // and then we may need to create a mapping
    if (_columns.length == 0) {
      _columnsByName = Collections.emptyMap();
    } else {
      _columnsByName = new HashMap<String, Column>(4 + _columns.length);
      for (Column c : _columns) {
        _columnsByName.put(c.getName(), c);
      }
    }
  }
  private int discardHead(
      ColumnFamily cf,
      int toDiscard,
      ColumnFamily copy,
      Iterator<Column> iter,
      DeletionInfo.InOrderTester tester) {
    ColumnCounter counter = columnCounter();

    List<Column> staticColumns = new ArrayList<>(cfm.staticColumns().size());

    // Discard the first 'toDiscard' live, non-static columns
    while (iter.hasNext()) {
      Column c = iter.next();

      // if it's a static column, don't count it and save it to add to the trimmed results
      ColumnDefinition columnDef = cfm.getColumnDefinitionFromColumnName(c.name());
      if (columnDef != null && columnDef.type == ColumnDefinition.Type.STATIC) {
        staticColumns.add(c);
        continue;
      }

      counter.count(c, tester);

      // once we've discarded the required amount, add the rest
      if (counter.live() > toDiscard) {
        for (Column staticColumn : staticColumns) copy.addColumn(staticColumn);

        copy.addColumn(c);
        while (iter.hasNext()) copy.addColumn(iter.next());
      }
    }
    return Math.min(counter.live(), toDiscard);
  }
 /**
  * Mutant factory method that will construct a new instance in which columns are sorted using
  * given {@link Comparator} over column names.
  *
  * @since 2.4
  */
 public CsvSchema sortedBy(Comparator<String> cmp) {
   TreeMap<String, Column> map = new TreeMap<String, Column>(cmp);
   for (Column col : _columns) {
     map.put(col.getName(), col);
   }
   return new CsvSchema(this, map.values().toArray(new Column[map.size()]));
 }
 /**
  * Returns the first non-static cell in the ColumnFamily. This is necessary to avoid recording a
  * static column as the "last" cell seen in a reversed query. Because we will always query static
  * columns alongside the normal data for a page, they are not a good indicator of where paging
  * should resume. When we begin the next page, we need to start from the last non-static cell.
  */
 protected Column firstNonStaticColumn(ColumnFamily cf) {
   for (Column column : cf) {
     ColumnDefinition def = cfm.getColumnDefinitionFromColumnName(column.name());
     if (def == null || def.type != ColumnDefinition.Type.STATIC) return column;
   }
   return null;
 }
Beispiel #5
0
 private Column undeclaredHKeyColumn(HKeyColumn hKeyColumn) {
   Column undeclaredHKeyColumn = null;
   int rootMostDepth = rootMostTable().getDepth();
   List<Column> equivalentColumns = hKeyColumn.equivalentColumns();
   switch (getJoinType()) {
     case LEFT:
       // use a rootward bias, but no more rootward than the rootmost table
       for (Column equivalentColumn : equivalentColumns) {
         int equivalentColumnDepth = equivalentColumn.getTable().getDepth();
         if (undeclaredHKeyColumn == null && equivalentColumnDepth >= rootMostDepth) {
           undeclaredHKeyColumn = equivalentColumn;
         }
       }
       break;
     case RIGHT:
       // use a leafward bias, but no more leafward than the leafdmost table
       int leafMostDepth = leafMostTable().getDepth();
       for (ListIterator<Column> reverseCols =
               equivalentColumns.listIterator(equivalentColumns.size());
           reverseCols.hasPrevious(); ) {
         Column equivalentColumn = reverseCols.previous();
         int equivalentColumnDepth = equivalentColumn.getTable().getDepth();
         if (undeclaredHKeyColumn == null && equivalentColumnDepth <= leafMostDepth) {
           undeclaredHKeyColumn = equivalentColumn;
         }
       }
       break;
   }
   if (undeclaredHKeyColumn == null) {
     undeclaredHKeyColumn = hKeyColumn.column();
   }
   return undeclaredHKeyColumn;
 }
Beispiel #6
0
  public void normalize() {
    for (int i = 0; i < samples.size(); i++) {
      TreeSet<Column.Entry> entries = new TreeSet<Column.Entry>();
      for (int j = 0; j < cols.size(); j++) {
        Column c = cols.get(j);
        if (c.values.get(i) != null) {
          entries.add(c.entry(i));
        }
      }

      int ns = entries.size();
      int j = 0;
      for (Column.Entry e : entries) {
        int cidx = ids.get(e.id());
        float ff = (float) j / (float) ns;
        cols.get(cidx).values.set(i, ff);
      }

      if (i > 0) {
        if (i % 100 == 0) {
          System.out.print(".");
          System.out.flush();
        }
      }
    }
    System.out.println();
  }
 /**
  * Optimized variant where a hint is given as to likely index of the column name.
  *
  * @since 2.6
  */
 public Column column(String name, int probableIndex) {
   if (probableIndex < _columns.length) {
     Column col = _columns[probableIndex];
     if (col.hasName(name)) {
       return col;
     }
   }
   return _columnsByName.get(name);
 }
Beispiel #8
0
 public void outputBinary(DataOutputStream dos) throws IOException {
   dos.writeInt(samples.size());
   for (String s : samples) {
     dos.writeUTF(s);
   }
   dos.writeInt(cols.size());
   for (Column c : cols) {
     c.outputBinary(dos);
   }
 }
Beispiel #9
0
 public void close() {
   for (Column pkColumn : table.getPrimaryKeyIncludingInternal().getColumns()) {
     inIndex.set(pkColumn.getPosition(), true);
   }
   if (table.getParentJoin() != null) {
     for (JoinColumn joinColumn : table.getParentJoin().getJoinColumns()) {
       inIndex.set(joinColumn.getChild().getPosition(), true);
     }
   }
 }
Beispiel #10
0
 private static int columnPosition(
     Map<? extends Table, Integer> flattenedRowOffsets, Column column) {
   int position = column.getPosition();
   Integer offset = flattenedRowOffsets.get(column.getTable());
   if (offset == null) {
     throw new NullPointerException(
         "no offset for " + column.getTable() + " in " + flattenedRowOffsets);
   }
   position += offset;
   return position;
 }
  /**
   * Returns a representation of of the population in the form of a table, where each row represents
   * one individual, one parameter per column, and the last column containing the objective value.
   *
   * @returns a table represeting the population.
   */
  public Table getTable() {

    Table vt;

    int rowCount = solutions.length;
    int colCount = ranges.length + 1;

    Column[] cols = new Column[colCount];

    // make a column for each range
    for (int i = 0; i < ranges.length; i++) {
      Column c;

      if (ranges[i] instanceof DoubleRange) {
        c = new DoubleColumn(rowCount);
        for (int j = 0; j < rowCount; j++) {
          double d = solutions[j].getDoubleParameter(i);
          ((DoubleColumn) c).setDouble(d, j);
        }
      } else if (ranges[i] instanceof IntRange) {
        c = new IntColumn(rowCount);
        for (int j = 0; j < rowCount; j++) {
          int in = (int) solutions[j].getDoubleParameter(i);
          ((IntColumn) c).setInt(in, j);
        }
      } else if (ranges[i] instanceof BinaryRange) {
        c = new BooleanColumn(rowCount);
        for (int j = 0; j < rowCount; j++) {
          boolean b = (solutions[j].getDoubleParameter(i) > 0);
          ((BooleanColumn) c).setBoolean(b, j);
        }
      } else { // i guess default to a double column
        c = new DoubleColumn(rowCount);
        for (int j = 0; j < rowCount; j++) {
          double d = solutions[j].getDoubleParameter(i);
          ((DoubleColumn) c).setDouble(d, j);
        }
      }

      c.setLabel(ranges[i].getName());
      cols[i] = c;
    }
    // now the objective
    DoubleColumn objC = new DoubleColumn(rowCount);
    objC.setLabel(objConstraints.getName());
    for (int j = 0; j < rowCount; j++) {
      objC.setDouble(solutions[j].getObjective(), j);
    }
    cols[colCount - 1] = objC;

    vt = new MutableTableImpl(cols);
    return vt;
  }
 /**
  * Mutant factory method that will construct a new instance in which columns are sorted based on
  * names given as argument. Columns not listed in argument will be sorted after those within list,
  * using existing ordering.
  *
  * <p>For example, schema that has columns:
  *
  * <pre>"a", "d", "c", "b"
  * </pre>
  *
  * ordered with <code>schema.sortedBy("a", "b");</code> would result instance that columns in
  * order:
  *
  * <pre>"a", "b", "d", "c"
  * </pre>
  *
  * @since 2.4
  */
 public CsvSchema sortedBy(String... columnNames) {
   LinkedHashMap<String, Column> map = new LinkedHashMap<String, Column>();
   for (String colName : columnNames) {
     Column col = _columnsByName.get(colName);
     if (col != null) {
       map.put(col.getName(), col);
     }
   }
   for (Column col : _columns) {
     map.put(col.getName(), col);
   }
   return new CsvSchema(this, map.values().toArray(new Column[map.size()]));
 }
Beispiel #13
0
  public RowMutation toSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    ColumnFamily cf = rm.addOrGet(SystemTable.SCHEMA_KEYSPACES_CF);

    cf.addColumn(Column.create(name, timestamp, "name"));
    cf.addColumn(Column.create(durableWrites, timestamp, "durable_writes"));
    cf.addColumn(Column.create(strategyClass.getName(), timestamp, "strategy_class"));
    cf.addColumn(Column.create(json(strategyOptions), timestamp, "strategy_options"));

    for (CFMetaData cfm : cfMetaData.values()) cfm.toSchema(rm, timestamp);

    return rm;
  }
 /** Method for getting description of column definitions in developer-readable form */
 public String getColumnDesc() {
   StringBuilder sb = new StringBuilder(100);
   for (Column col : _columns) {
     if (sb.length() == 0) {
       sb.append('[');
     } else {
       sb.append(',');
     }
     sb.append('"');
     sb.append(col.getName());
     sb.append('"');
   }
   sb.append(']');
   return sb.toString();
 }
Beispiel #15
0
 private static void addAdviceToMatchedCube(Advice advice, String regex, NCube ncube, Axis axis) {
   if (axis != null) { // Controller methods
     for (Column column : axis.getColumnsWithoutDefault()) {
       String method = column.getValue().toString();
       String classMethod = ncube.getName() + '.' + method + "()";
       if (classMethod.matches(regex)) {
         ncube.addAdvice(advice, method);
       }
     }
   } else { // Expressions
     String classMethod = ncube.getName() + ".run()";
     if (classMethod.matches(regex)) {
       ncube.addAdvice(advice, "run");
     }
   }
 }
  @Override
  public Table showTableDetails(UUID subscriptionId, String serviceName, String tableName)
      throws AzureCmdException {
    String[] cmd =
        new String[] {
          "mobile",
          "table",
          "show",
          "--json",
          "-s",
          subscriptionId.toString(),
          serviceName,
          tableName
        };

    String json = AzureCommandHelper.getInstance().consoleExec(cmd);

    CustomJsonSlurper slurper = new CustomJsonSlurper();
    Map<String, Object> tempRes = (Map<String, Object>) slurper.parseText(json);

    Table t = new Table();

    Map<String, Object> tableData = (Map<String, Object>) tempRes.get("table");
    t.setName(tableData.get("name").toString());
    t.setSelfLink(tableData.get("selflink").toString());

    Map<String, String> per = (Map<String, String>) tempRes.get("permissions");

    TablePermissions tablePermissions = new TablePermissions();
    tablePermissions.setInsert(PermissionItem.getPermitionType(per.get("insert")));
    tablePermissions.setUpdate(PermissionItem.getPermitionType(per.get("update")));
    tablePermissions.setRead(PermissionItem.getPermitionType(per.get("read")));
    tablePermissions.setDelete(PermissionItem.getPermitionType(per.get("delete")));
    t.setTablePermissions(tablePermissions);

    for (Map<String, Object> column : (List<Map<String, Object>>) tempRes.get("columns")) {
      Column c = new Column();
      c.setName(column.get("name").toString());
      c.setType(column.get("type").toString());
      c.setSelfLink(column.get("selflink").toString());
      c.setIndexed((Boolean) column.get("indexed"));
      c.setZumoIndex((Boolean) column.get("zumoIndex"));

      t.getColumns().add(c);
    }

    for (Map<String, Object> script : (List<Map<String, Object>>) tempRes.get("scripts")) {
      Script s = new Script();

      s.setOperation(script.get("operation").toString());
      s.setBytes((Integer) script.get("sizeBytes"));
      s.setSelfLink(script.get("selflink").toString());
      s.setName(String.format("%s.%s", tableData.get("name"), script.get("operation").toString()));

      t.getScripts().add(s);
    }

    return t;
  }
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder(150);
    sb.append("[CsvSchema: ").append("columns=[");
    boolean first = true;
    for (Column col : _columns) {
      if (first) {
        first = false;
      } else {
        sb.append(',');
      }
      sb.append('"');
      sb.append(col.getName());
      sb.append("\"/");
      sb.append(col.getType());
    }
    sb.append(']');
    sb.append(", header? ").append(usesHeader());
    sb.append(", skipFirst? ").append(skipsFirstDataRow());
    sb.append(", comments?? ").append(allowsComments());

    sb.append(']');
    return sb.toString();
  }
  public void testSendRows() throws SmartsheetException, IOException {
    // Specify individual recipient.
    RecipientEmail recipientEmail =
        new RecipientEmail.AddRecipientEmailBuilder().setEmail("*****@*****.**").build();

    List<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(recipientEmail);

    MultiRowEmail multiRowEmail =
        new MultiRowEmail.AddMultiRowEmailBuilder()
            .setSendTo(recipients)
            .setSubject("some subject")
            .setMessage("some message")
            .setCcMe(false)
            .setRowIds(Arrays.asList(newRows.get(0).getId()))
            .setColumnIds(Arrays.asList(addedColumn.getId()))
            .setIncludeAttachments(false)
            .setIncludeDiscussions(false)
            .build();

    smartsheet.sheetResources().rowResources().sendRows(sheet.getId(), multiRowEmail);
  }
  public void testAddRows() throws SmartsheetException, IOException {
    // create sheet
    sheet = smartsheet.sheetResources().createSheet(createSheetObject());

    // get column
    PaginationParameters parameters =
        new PaginationParameters.PaginationParametersBuilder().setIncludeAll(true).build();
    PagedResult<Column> wrapper =
        smartsheet
            .sheetResources()
            .columnResources()
            .listColumns(sheet.getId(), EnumSet.allOf(ColumnInclusion.class), parameters);

    Column addedColumn1 = wrapper.getData().get(0);
    Column addedColumn2 = wrapper.getData().get(1);

    // Specify cell values for first row.
    List<Cell> cellsA =
        new Cell.AddRowCellsBuilder()
            .addCell(addedColumn1.getId(), true)
            .addCell(addedColumn2.getId(), "New status")
            .build();

    // Specify contents of first row.
    row = new Row.AddRowBuilder().setCells(cellsA).setToBottom(true).build();

    // Specify cell values for second row.
    List<Cell> cellsB =
        new Cell.AddRowCellsBuilder()
            .addCell(addedColumn1.getId(), true)
            .addCell(addedColumn2.getId(), "New status")
            .build();

    // Specify contents of first row.
    Row rowA = new Row.AddRowBuilder().setCells(cellsB).setToBottom(true).build();

    newRows =
        smartsheet.sheetResources().rowResources().addRows(sheet.getId(), Arrays.asList(row, rowA));

    List<Column> columns = wrapper.getData();
    addedColumn = columns.get(1);
  }
  @Test
  public void testUpdateRows() throws SmartsheetException, IOException {
    // create sheet
    Sheet sheet = smartsheet.sheetResources().createSheet(createSheetObject());
    PaginationParameters parameters =
        new PaginationParameters.PaginationParametersBuilder().setIncludeAll(true).build();
    PagedResult<Column> wrapper =
        smartsheet
            .sheetResources()
            .columnResources()
            .listColumns(sheet.getId(), EnumSet.allOf(ColumnInclusion.class), parameters);

    Column addedColumn1 = wrapper.getData().get(0);
    Column addedColumn2 = wrapper.getData().get(1);

    // Specify cell values for first row.
    List<Cell> cellsA =
        new Cell.AddRowCellsBuilder()
            .addCell(addedColumn1.getId(), true)
            .addCell(addedColumn2.getId(), "New status")
            .build();

    // Specify contents of first row.
    Row row = new Row.AddRowBuilder().setCells(cellsA).setToBottom(true).build();
    List<Row> newRows =
        smartsheet.sheetResources().rowResources().addRows(sheet.getId(), Arrays.asList(row));

    // Updated cells //correct
    List<Cell> cellsB =
        new Cell.UpdateRowCellsBuilder()
            .addCell(addedColumn1.getId(), true)
            .addCell(addedColumn2.getId(), "Updtaed status")
            .build();

    Row rowB = new Row.UpdateRowBuilder().setCells(cellsB).setRowId(newRows.get(0).getId()).build();

    List<Row> updatedRows =
        smartsheet.sheetResources().rowResources().updateRows(sheet.getId(), Arrays.asList(rowB));

    assertNotNull(updatedRows);
    deleteSheet(sheet.getId());
  }
Beispiel #21
0
 public void markInvolvedInIndex(Column column) {
   assert column.getTable() == table;
   inIndex.set(column.getPosition(), true);
 }
Beispiel #22
0
 private int depth(Column column) {
   return column.getTable().getDepth();
 }
Beispiel #23
0
  private void createDataGrid() {
    dataGrid = new DataGrid<InputItem>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<InputItem>(KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    recordStore = new ListDataProvider<InputItem>(KEY_PROVIDER);
    recordStore.addDataDisplay(dataGrid);

    sortHandler = new ColumnSortEvent.ListHandler<InputItem>(recordStore.getList());

    Column<InputItem, InputItem> colId = new IdentityColumn<InputItem>(ID_CELL);
    dataGrid.addColumn(colId, new ResizableHeader<InputItem>("#", dataGrid, colId));
    dataGrid.setColumnWidth(colId, 35, Style.Unit.PX);

    final EditTextCell cellName = new EditTextCell();
    Column<InputItem, String> colName =
        new Column<InputItem, String>(cellName) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getName();
          }
        };
    colName.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getName())) {
              markChange(rec);
              rec.setName(value);
              cellName.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colName, new ResizableHeader<InputItem>("Name", dataGrid, colName));
    dataGrid.setColumnWidth(colName, 128, Style.Unit.PX);

    colName.setSortable(true);
    sortHandler.setComparator(
        colName,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    //        final SelectCell<String,Integer> cellActive = new SelectCell<String,Integer>(
    //                ZicoWidgets.<String,Integer>map("NO",0,"YES",1));
    //        Column<InputItem,Integer> colActive = new Column<InputItem, Integer>(cellActive) {
    //            @Override
    //            public Integer getValue(InputItem rec) {
    //                return rec.getActive();
    //            }
    //        };
    //        colActive.setFieldUpdater(new FieldUpdater<InputItem, Integer>() {
    //            @Override
    //            public void update(int index, InputItem rec, Integer value) {
    //                if (rec.getActive() != value) {
    //                    markChange(rec);
    //                    rec.setActive(value);
    //                    cellActive.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        dataGrid.addColumn(colActive, new ResizableHeader<InputItem>("Active", dataGrid,
    // colActive));
    //        dataGrid.setColumnWidth(colActive, 128, Style.Unit.PX);

    //        final DatePickerCell cellTstart = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstart = new Column<InputItem, Date>(cellTstart) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstart());
    //            }
    //        };
    //        colTstart.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstart()) {
    //                    markChange(rec);
    //                    rec.setTstart(t);
    //                    cellTstart.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstart.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstart, new ResizableHeader<InputItem>("TStart", dataGrid,
    // colTstart));
    //        dataGrid.setColumnWidth(colTstart, 100, Style.Unit.PX);

    //        final DatePickerCell cellTstop = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstop = new Column<InputItem, Date>(cellTstop) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstop());
    //            }
    //        };
    //        colTstop.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstop()) {
    //                    markChange(rec);
    //                    rec.setTstop(t);
    //                    cellTstop.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstop.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstop, new ResizableHeader<InputItem>("TStop", dataGrid,
    // colTstop));
    //        dataGrid.setColumnWidth(colTstop, 100, Style.Unit.PX);

    Column<InputItem, Integer> colInput =
        new Column<InputItem, Integer>(cellInput) {
          @Override
          public Integer getValue(InputItem iitem) {
            return iitem.getInputId();
          }
        };
    colInput.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem rec, Integer value) {
            if (rec.getInputId() != value) {
              markChange(rec);
              rec.setInputId(value);
              cellInput.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colInput, new ResizableHeader<InputItem>("Input", dataGrid, colInput));
    dataGrid.setColumnWidth(colInput, 128, Style.Unit.PX);

    Column<InputItem, Integer> colTxForm =
        new Column<InputItem, Integer>(cellTxForm) {
          @Override
          public Integer getValue(InputItem rec) {
            return rec.getTxFormid();
          }
        };
    colTxForm.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem iitem, Integer value) {
            if (iitem.getTxFormid() != value) {
              markChange(iitem);
              iitem.setTxFormid(value);
              cellTxForm.clearViewData(iitem.getId());
            }
          }
        });
    dataGrid.addColumn(colTxForm, new ResizableHeader<InputItem>("TxForm", dataGrid, colTxForm));
    dataGrid.setColumnWidth(colTxForm, 128, Style.Unit.PX);

    final EditTextCell cellComment = new EditTextCell();
    Column<InputItem, String> colComment =
        new Column<InputItem, String>(cellComment) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getComment();
          }
        };
    colComment.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getComment())) {
              markChange(rec);
              rec.setComment(value);
              cellComment.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colComment, new ResizableHeader<InputItem>("Comment", dataGrid, colComment));

    colComment.setSortable(true);
    sortHandler.setComparator(
        colComment,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getComment().compareTo(o2.getComment());
          }
        });

    dataGrid.addCellPreviewHandler(
        new CellPreviewEvent.Handler<InputItem>() {
          @Override
          public void onCellPreview(CellPreviewEvent<InputItem> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
              selectionModel.setSelected(event.getValue(), true);
              if (event.getValue() != null) {
                contextMenu.setPopupPosition(
                    event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                contextMenu.show();
              }
            }
          }
        });

    dataGrid.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
          }
        },
        DoubleClickEvent.getType());
    dataGrid.addDomHandler(
        new ContextMenuHandler() {
          @Override
          public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
          }
        },
        ContextMenuEvent.getType());
  }
Beispiel #24
0
  /**
   * 事实表和关联报表属于当前传入数组的交叉报表
   *
   * @param request
   * @param tables elements are table.id
   * @return elements are ArrayList, first is cxtab id, second is cxtab name
   */
  public List getCxtabs(HttpServletRequest request, List<Integer> tables) {
    TableManager manager = TableManager.getInstance();
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < tables.size(); i++) {
      // Table t= tables.get(i);
      if (i > 0) sb.append(",");
      sb.append(tables.get(i));
    }
    String ts = sb.toString();
    try {
      Table cxtabTable = manager.getTable("AD_CXTAB");
      QueryRequestImpl queryData;
      // only pk,dk will be selected, order by ak asc
      queryData = QueryEngine.getInstance().createRequest(userWeb.getSession());
      queryData.setMainTable(cxtabTable.getId());

      queryData.addSelection(cxtabTable.getPrimaryKey().getId());
      queryData.addSelection(cxtabTable.getDisplayKey().getId());

      Column colOrderNo = cxtabTable.getColumn("orderno");
      queryData.setOrderBy(new int[] {colOrderNo.getId()}, true);
      queryData.setRange(0, Integer.MAX_VALUE);

      Expression expr =
          new Expression(
              null,
              "(AD_CXTAB.AD_TABLE_ID in ("
                  + ts
                  + ") or exists (select 1 from ad_cxtab_reftable r where r.ad_cxtab_id=AD_CXTAB.id and r.ad_table_id in ("
                  + ts
                  + ")))",
              null);

      // set reporttype to "S"
      expr =
          expr.combine(
              new Expression(new ColumnLink("AD_CXTAB.REPORTTYPE"), "=S", null),
              SQLCombination.SQL_AND,
              null);
      expr =
          expr.combine(
              new Expression(new ColumnLink("AD_CXTAB.ISACTIVE"), "=Y", null),
              SQLCombination.SQL_AND,
              null);
      expr =
          expr.combine(
              new Expression(new ColumnLink("AD_CXTAB.ISPUBLIC"), "=Y", null),
              SQLCombination.SQL_AND,
              null);
      expr =
          expr.combine(
              userWeb.getSecurityFilter(cxtabTable.getName(), 1), SQLCombination.SQL_AND, null);
      queryData.addParam(expr); // read permission

      return QueryEngine.getInstance().doQueryList(queryData.toSQL());
    } catch (Throwable t) {
      logger.error(
          "Fail to load reports for user " + userWeb.getUserId() + " with table ids: " + ts, t);
    }
    return Collections.EMPTY_LIST;
  }
Beispiel #25
0
 public boolean isDeleted(Column column) {
   return isDeleted(column.name(), column.timestamp());
 }
Beispiel #26
0
  @Override
  public final void createTable(final CatalogProtos.TableDescProto tableDescProto)
      throws CatalogException {
    HiveCatalogStoreClientPool.HiveCatalogStoreClient client = null;

    TableDesc tableDesc = new TableDesc(tableDescProto);
    String[] splitted = CatalogUtil.splitFQTableName(tableDesc.getName());
    String databaseName = splitted[0];
    String tableName = splitted[1];

    try {
      client = clientPool.getClient();

      org.apache.hadoop.hive.metastore.api.Table table =
          new org.apache.hadoop.hive.metastore.api.Table();
      table.setDbName(databaseName);
      table.setTableName(tableName);
      table.setParameters(
          new HashMap<String, String>(tableDesc.getMeta().getOptions().getAllKeyValus()));
      // TODO: set owner
      // table.setOwner();

      StorageDescriptor sd = new StorageDescriptor();
      sd.setSerdeInfo(new SerDeInfo());
      sd.getSerdeInfo().setParameters(new HashMap<String, String>());
      sd.getSerdeInfo().setName(table.getTableName());

      // if tajo set location method, thrift client make exception as follows:
      // Caused by: MetaException(message:java.lang.NullPointerException)
      // If you want to modify table path, you have to modify on Hive cli.
      if (tableDesc.isExternal()) {
        table.setTableType(TableType.EXTERNAL_TABLE.name());
        table.putToParameters("EXTERNAL", "TRUE");

        Path tablePath = new Path(tableDesc.getUri());
        FileSystem fs = tablePath.getFileSystem(conf);
        if (fs.isFile(tablePath)) {
          LOG.warn("A table path is a file, but HiveCatalogStore does not allow a file path.");
          sd.setLocation(tablePath.getParent().toString());
        } else {
          sd.setLocation(tablePath.toString());
        }
      }

      // set column information
      List<Column> columns = tableDesc.getSchema().getRootColumns();
      ArrayList<FieldSchema> cols = new ArrayList<FieldSchema>(columns.size());

      for (Column eachField : columns) {
        cols.add(
            new FieldSchema(
                eachField.getSimpleName(),
                HiveCatalogUtil.getHiveFieldType(eachField.getDataType()),
                ""));
      }
      sd.setCols(cols);

      // set partition keys
      if (tableDesc.hasPartition()
          && tableDesc.getPartitionMethod().getPartitionType().equals(PartitionType.COLUMN)) {
        List<FieldSchema> partitionKeys = new ArrayList<FieldSchema>();
        for (Column eachPartitionKey :
            tableDesc.getPartitionMethod().getExpressionSchema().getRootColumns()) {
          partitionKeys.add(
              new FieldSchema(
                  eachPartitionKey.getSimpleName(),
                  HiveCatalogUtil.getHiveFieldType(eachPartitionKey.getDataType()),
                  ""));
        }
        table.setPartitionKeys(partitionKeys);
      }

      if (tableDesc.getMeta().getStoreType().equalsIgnoreCase(BuiltinStorages.RCFILE)) {
        String serde = tableDesc.getMeta().getOption(StorageConstants.RCFILE_SERDE);
        sd.setInputFormat(org.apache.hadoop.hive.ql.io.RCFileInputFormat.class.getName());
        sd.setOutputFormat(org.apache.hadoop.hive.ql.io.RCFileOutputFormat.class.getName());
        if (StorageConstants.DEFAULT_TEXT_SERDE.equals(serde)) {
          sd.getSerdeInfo()
              .setSerializationLib(
                  org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe.class.getName());
        } else {
          sd.getSerdeInfo()
              .setSerializationLib(
                  org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe.class.getName());
        }

        if (tableDesc.getMeta().getOptions().containsKey(StorageConstants.RCFILE_NULL)) {
          table.putToParameters(
              serdeConstants.SERIALIZATION_NULL_FORMAT,
              StringEscapeUtils.unescapeJava(
                  tableDesc.getMeta().getOption(StorageConstants.RCFILE_NULL)));
        }
      } else if (tableDesc.getMeta().getStoreType().equals(BuiltinStorages.TEXT)) {
        sd.getSerdeInfo()
            .setSerializationLib(
                org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());
        sd.setInputFormat(org.apache.hadoop.mapred.TextInputFormat.class.getName());
        sd.setOutputFormat(
            org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat.class.getName());

        String fieldDelimiter =
            tableDesc
                .getMeta()
                .getOption(
                    StorageConstants.TEXT_DELIMITER, StorageConstants.DEFAULT_FIELD_DELIMITER);

        // User can use an unicode for filed delimiter such as \u0001, \001.
        // In this case, java console will convert this value into "\\u001".
        // And hive will un-espace this value again.
        // As a result, user can use right field delimiter.
        // So, we have to un-escape this value.
        sd.getSerdeInfo()
            .putToParameters(
                serdeConstants.SERIALIZATION_FORMAT,
                StringEscapeUtils.unescapeJava(fieldDelimiter));
        sd.getSerdeInfo()
            .putToParameters(
                serdeConstants.FIELD_DELIM, StringEscapeUtils.unescapeJava(fieldDelimiter));
        table.getParameters().remove(StorageConstants.TEXT_DELIMITER);

        if (tableDesc.getMeta().containsOption(StorageConstants.TEXT_NULL)) {
          table.putToParameters(
              serdeConstants.SERIALIZATION_NULL_FORMAT,
              StringEscapeUtils.unescapeJava(
                  tableDesc.getMeta().getOption(StorageConstants.TEXT_NULL)));
          table.getParameters().remove(StorageConstants.TEXT_NULL);
        }
      } else if (tableDesc
          .getMeta()
          .getStoreType()
          .equalsIgnoreCase(BuiltinStorages.SEQUENCE_FILE)) {
        String serde = tableDesc.getMeta().getOption(StorageConstants.SEQUENCEFILE_SERDE);
        sd.setInputFormat(org.apache.hadoop.mapred.SequenceFileInputFormat.class.getName());
        sd.setOutputFormat(
            org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat.class.getName());

        if (StorageConstants.DEFAULT_TEXT_SERDE.equals(serde)) {
          sd.getSerdeInfo()
              .setSerializationLib(
                  org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe.class.getName());

          String fieldDelimiter =
              tableDesc
                  .getMeta()
                  .getOption(
                      StorageConstants.SEQUENCEFILE_DELIMITER,
                      StorageConstants.DEFAULT_FIELD_DELIMITER);

          // User can use an unicode for filed delimiter such as \u0001, \001.
          // In this case, java console will convert this value into "\\u001".
          // And hive will un-espace this value again.
          // As a result, user can use right field delimiter.
          // So, we have to un-escape this value.
          sd.getSerdeInfo()
              .putToParameters(
                  serdeConstants.SERIALIZATION_FORMAT,
                  StringEscapeUtils.unescapeJava(fieldDelimiter));
          sd.getSerdeInfo()
              .putToParameters(
                  serdeConstants.FIELD_DELIM, StringEscapeUtils.unescapeJava(fieldDelimiter));
          table.getParameters().remove(StorageConstants.SEQUENCEFILE_DELIMITER);
        } else {
          sd.getSerdeInfo()
              .setSerializationLib(
                  org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe.class.getName());
        }

        if (tableDesc.getMeta().containsOption(StorageConstants.SEQUENCEFILE_NULL)) {
          table.putToParameters(
              serdeConstants.SERIALIZATION_NULL_FORMAT,
              StringEscapeUtils.unescapeJava(
                  tableDesc.getMeta().getOption(StorageConstants.SEQUENCEFILE_NULL)));
          table.getParameters().remove(StorageConstants.SEQUENCEFILE_NULL);
        }
      } else {
        if (tableDesc.getMeta().getStoreType().equalsIgnoreCase(BuiltinStorages.PARQUET)) {
          sd.setInputFormat(parquet.hive.DeprecatedParquetInputFormat.class.getName());
          sd.setOutputFormat(parquet.hive.DeprecatedParquetOutputFormat.class.getName());
          sd.getSerdeInfo()
              .setSerializationLib(parquet.hive.serde.ParquetHiveSerDe.class.getName());
        } else {
          throw new UnsupportedException(
              tableDesc.getMeta().getStoreType() + " in HivecatalogStore");
        }
      }

      sd.setSortCols(new ArrayList<Order>());

      table.setSd(sd);
      client.getHiveClient().createTable(table);
    } catch (Throwable t) {
      throw new TajoInternalError(t);
    } finally {
      if (client != null) client.release();
    }
  }
  private void jbInit() throws Exception {
    dbAlias = com.limosys.dbaccess.Connection.getAddress(dbAlias);
    dbAlias.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
    dbAlias.setUseStatementCaching(false);

    pRowSelect.addColumn("ID", Variant.INT);

    colId.setColumnName("ID");
    colId.setServerColumnName("ID");
    colId.setTableName("T_6467063785");
    colId.setRowId(true);
    colId.setDataType(Variant.INT);
    colId.setSqlType(4);
    colName.setColumnName("NAME");
    colName.setServerColumnName("NAME");
    colName.setTableName("T_6467063785");
    colName.setDataType(Variant.STRING);
    colName.setPrecision(255);
    colName.setSqlType(12);
    colCompanyName.setColumnName("COMPANY_NAME");
    colCompanyName.setServerColumnName("COMPANY_NAME");
    colCompanyName.setTableName("T_6467063785");
    colCompanyName.setDataType(Variant.STRING);
    colCompanyName.setPrecision(255);
    colCompanyName.setSqlType(12);
    prT_6467063785.setDatabase(dbAlias);
    // prT_6467063785.setInsertProcedure(new ProcedureDescriptor(dbAlias, "exec
    // lsp_T_6467063785_INotNull_v2  :ID, :NAME, :COMPANY_NAME", pdsT_6467063785, true, Load.ALL));
    prT_6467063785.setDeleteProcedure(
        new ProcedureDescriptor(
            dbAlias, "exec lsp_T_6467063785_D_v2  :ID", pdsT_6467063785, true, Load.ALL));
    pdsT_6467063785.setMetaDataUpdate(MetaDataUpdate.NONE);
    pdsT_6467063785.setResolver(prT_6467063785);
    pdsT_6467063785.setSchemaName("");
    pdsT_6467063785.setProcedure(
        new ProcedureDescriptor(
            dbAlias, "exec lsp_T_6467063785_SRow_v2 :ID", pRowSelect, true, Load.ALL));
    pdsT_6467063785.setColumns(new Column[] {colId, colName, colCompanyName});
  }