public Map<String, Long> getRegionSizes(String tableName) { Map<String, Long> regions = new HashMap<>(); try { final Table table = connection.getTable(TableName.valueOf(tableName)); RegionLocator regionLocator = connection.getRegionLocator(table.getName()); List<HRegionLocation> tableRegionInfos = regionLocator.getAllRegionLocations(); Set<byte[]> tableRegions = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR); for (HRegionLocation regionInfo : tableRegionInfos) { tableRegions.add(regionInfo.getRegionInfo().getRegionName()); } ClusterStatus clusterStatus = connection.getAdmin().getClusterStatus(); Collection<ServerName> servers = clusterStatus.getServers(); final long megaByte = 1024L * 1024L; for (ServerName serverName : servers) { ServerLoad serverLoad = clusterStatus.getLoad(serverName); for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) { byte[] regionId = regionLoad.getName(); if (tableRegions.contains(regionId)) { long regionSizeBytes = regionLoad.getStorefileSizeMB() * megaByte; regions.put(regionLoad.getNameAsString(), regionSizeBytes); } } } } catch (IOException e) { e.printStackTrace(); } return regions; }
public String addTableBody(Table table) { String name = SQLStringVisitor.escapeSinglePart(table.getName()); append(name); if (table.getColumns() != null) { append(SPACE); append(LPAREN); boolean first = true; for (Column c : table.getColumns()) { if (first) { first = false; } else { append(COMMA); } visit(table, c); } buildContraints(table); append(NEWLINE); append(RPAREN); } // options String options = buildTableOptions(table); if (!options.isEmpty()) { append(SPACE).append(OPTIONS).append(SPACE).append(LPAREN).append(options).append(RPAREN); } return name; }
public void execute(Table table, int posx, int posy, int startX, int startY, int endX, int endY) { float min = Float.MAX_VALUE; boolean floating = false; for (int x = startX; x <= endX; x++) { for (int y = startY; y <= endY; y++) { // Logger.debug("x="+x+" y="+y+" >"+getXY(x,y)); float value = 0; try { value += Integer.parseInt((String) table.getXY(x, y)); } catch (Exception e) { try { value += Float.parseFloat((String) table.getXY(x, y)); floating = true; } catch (NumberFormatException e1) { log.debug("SumFunction: unable to parse " + table.getXY(x, y)); } } if (min > value) { min = value; } } } // Logger.debug("Sum="+sum); if (floating) { table.setXY(posx, posy, "" + min); } else { table.setXY(posx, posy, "" + (int) min); } }
private String buildInsertStatement() { StringBuilder sql = new StringBuilder(); sql.append("insert into ").append(into.name()); sql.append("(").append(JDBC.asString(into.columnNames())).append(")"); sql.append(" values(").append(JDBC.asString(parametersFor(into.columnNames()))).append(")"); return sql.toString(); }
/** * Constructor declaration * * @param t * @param alias * @param outerjoin */ TableFilter(Table t, String alias, boolean outerjoin) { filterTable = t; tableAlias = alias == null ? t.getName().name : alias; isOuterJoin = outerjoin; emptyData = filterTable.getNewRow(); }
public synchronized void importCSV_stats( String originalCsvFile, String parsedCsvFile, String destinationTable) { this.originalCsvFile = originalCsvFile; this.csvFile = parsedCsvFile; this.destinationTable = destinationTable; try { initLists(); setFileNameInterface(); grabStructures(); addMissingColumns(); if (table.createTempTable( "tmp_" + destinationTable, fileColumns, fileColumnType, fileColumnSize)) { removeCSVheading(); if (table.importFileToTable(originalCsvFile, parsedCsvFile, "tmp_" + destinationTable)) { addColumn(); if (updateColumn()) { createIndex(); if (copyFromTableToTable()) { fileNameInterface.storeSuccessfulFile(con, new File(originalCsvFile)); updateColumn(); } } else { System.err.println( getCurrentDateTime() + "->Error importing " + originalCsvFile + ": Columns needed for concatenation not found"); fileNameInterface.storeErrorFile(con, new File(originalCsvFile)); } } } } catch (Exception ex) { System.err.println(getCurrentDateTime() + "->Error importing " + originalCsvFile + ": " + ex); } }
private void initVars() { vars = new Table(); vars.put( symbol("malloc"), new VarEntry( new FUNCTION( new RECORD(symbol("s"), Type.INT, null), Type.VOIDPTR, false, new Label("malloc")))); vars.put( symbol("strcpy"), new VarEntry( new FUNCTION( new RECORD( symbol("s1"), Type.CHARPTR, new RECORD( symbol("s2"), Type.CHARPTR, new RECORD(symbol("size"), Type.INT, null))), Type.CHARPTR, false, new Label("strcpy")))); vars.put( symbol("printf"), new VarEntry( new FUNCTION( new RECORD(symbol("s"), Type.CHARPTR, null), Type.INT, true, new Label("printf")))); }
@Test public void testRemoveColumnFamily() throws IOException, ExecutionException, InterruptedException { Table table = Table.open("Keyspace1"); ColumnFamilyStore store = table.getColumnFamilyStore("Standard1"); RowMutation rm; // add data rm = new RowMutation("Keyspace1", "key1"); rm.add(new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), 0); rm.apply(); // remove rm = new RowMutation("Keyspace1", "key1"); rm.delete(new QueryPath("Standard1"), 1); rm.apply(); ColumnFamily retrieved = store.getColumnFamily( new IdentityQueryFilter( "key1", new QueryPath("Standard1", null, "Column1".getBytes()))); assert retrieved.isMarkedForDelete(); assertNull(retrieved.getColumn("Column1".getBytes())); assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE)); }
protected void handleAckReceived(Address sender, long seqno, short conn_id) { if (log.isTraceEnabled()) log.trace( new StringBuilder() .append(local_addr) .append(" <-- ACK(") .append(sender) .append(": #") .append(seqno) .append(", conn-id=") .append(conn_id) .append(')')); SenderEntry entry = send_table.get(sender); if (entry != null && entry.send_conn_id != conn_id) { if (log.isTraceEnabled()) log.trace( local_addr + ": my conn_id (" + entry.send_conn_id + ") != received conn_id (" + conn_id + "); discarding ACK"); return; } Table<Message> win = entry != null ? entry.sent_msgs : null; if (win != null) { win.purge(seqno, true); // removes all messages <= seqno (forced purge) num_acks_received++; } }
private void getDatas(SearchBean searchBean) { totalNumber = codeDictMapper.getCount(searchBean); if (null != pageTool) { pageTool.setTotalNumber(totalNumber); pageTool.setBounds( new Rectangle(668 - pageTool.getPanelLength(), 455, pageTool.getPanelLength() - 3, 22)); } List<CodeDictBean> codeDictBeanList = codeDictMapper.selectCodeDictsByParams(searchBean); if (CollectionUtils.isNotEmpty(codeDictBeanList)) { rowData.clear(); parent.clear(); Map<String, Object> black = new HashMap<String, Object>(); black.put("label", ""); black.put("value", null); parent.add(black); for (CodeDictBean codeDictBean : codeDictBeanList) { rowData.add(buildVectorData(codeDictBean)); Map<String, Object> item = new HashMap<String, Object>(); item.put("label", codeDictBean.getId() + " - " + codeDictBean.getValue()); item.put("value", codeDictBean.getId()); parent.add(item); } } else { rowData.clear(); } if (table != null) { table.updateTable(); table.getColumnModel().getColumn(4).setCellEditor(new ComboBoxEditor(parent)); table.rows.clear(); } }
/** * Drops the index with the specified name from this database. * * @param indexname the name of the index to drop * @param ifExists if true and if the Index to drop does not exist, fail silently, else throw * @param session the execution context * @throws HsqlException if the index does not exist, the session lacks the permission or the * operation violates database integrity */ void dropIndex(Session session, String indexname, String tableName, boolean ifExists) throws HsqlException { Table t = findUserTableForIndex(session, indexname); if (t == null) { if (ifExists) { return; } else { throw Trace.error(Trace.INDEX_NOT_FOUND, indexname); } } if (tableName != null && !t.getName().name.equals(tableName)) { throw Trace.error(Trace.INDEX_NOT_FOUND, indexname); } t.checkDropIndex(indexname, null); // fredt@users 20020405 - patch 1.7.0 by fredt - drop index bug // see Table.moveDefinition(); session.commit(); session.setScripting(!t.isTemp()); TableWorks tw = new TableWorks(session, t); tw.dropIndex(indexname); }
/** * Returns the image stored at the given column index in the receiver, or null if the image has * not been set or if the column does not exist. * * @param index the column index * @return the image stored at the given column index in the receiver * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public Image getImage(final int index) { checkWidget(); if (!parent.checkData(this, parent.indexOf(this))) { error(SWT.ERROR_WIDGET_DISPOSED); } return getImageInternal(index); }
private int getSpacing(final int index) { int result = 0; if (parent.hasColumnImages(index)) { result = parent.getCellSpacing(); } return result; }
public Optional<byte[]> get( Optional<String> table, Optional<String> family, Optional<String> qualifier, Optional<String> key) { if (!valid) { Logger.error("CANNOT GET! NO VALID CONNECTION"); return Optional.empty(); } if (table.isPresent() && family.isPresent() && qualifier.isPresent() && key.isPresent() && !key.get().isEmpty()) { try { final Table htable = connection.getTable(TableName.valueOf(table.get())); Result result = htable.get(new Get(key.get().getBytes("UTF8"))); return Optional.ofNullable( result.getValue(family.get().getBytes("UTF8"), qualifier.get().getBytes("UTF8"))); } catch (IOException e) { e.printStackTrace(); } } return Optional.empty(); }
public static void sortTable(Table table, Comparator<TableItem> comparator) { int columnCount = table.getColumnCount(); String[] values = new String[columnCount]; TableItem[] items = table.getItems(); for (int i = 1; i < items.length; i++) { for (int j = 0; j < i; j++) { TableItem item = items[i]; if (comparator.compare(item, items[j]) < 0) { for (int k = 0; k < columnCount; k++) { values[k] = item.getText(k); } Object data = item.getData(); boolean checked = item.getChecked(); item.dispose(); item = new TableItem(table, SWT.NONE, j); item.setText(values); item.setData(data); item.setChecked(checked); items = table.getItems(); break; } } } }
@ManagedOperation( description = "Sends a STABLE message to all senders. This causes message purging and potential" + " retransmissions from senders") public void sendStableMessages() { for (Map.Entry<Address, ReceiverEntry> entry : recv_table.entrySet()) { Address dest = entry.getKey(); ReceiverEntry val = entry.getValue(); Table<Message> win = val != null ? val.received_msgs : null; if (win != null) { long[] tmp = win.getDigest(); long low = tmp[0], high = tmp[1]; if (val.last_highest == high) { if (val.num_stable_msgs >= max_stable_msgs) { continue; } else val.num_stable_msgs++; } else { val.last_highest = high; val.num_stable_msgs = 1; } sendStableMessage(dest, val.recv_conn_id, low, high); } } }
private Composite createAvailableList(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; container.setLayout(layout); container.setLayoutData(new GridData()); Label label = new Label(container, SWT.NONE); label.setText(PDEUIMessages.ImportWizard_DetailedPage_availableList); Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 200; gd.widthHint = 225; table.setLayoutData(gd); fAvailableListViewer = new TableViewer(table); fAvailableListViewer.setLabelProvider(new PluginImportLabelProvider()); fAvailableListViewer.setContentProvider(new ContentProvider()); fAvailableListViewer.setInput(PDECore.getDefault().getModelManager()); fAvailableListViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); return container; }
/** * We need to resend our first message with our conn_id * * @param sender * @param seqno Resend the non null messages in the range [lowest .. seqno] */ protected void handleResendingOfFirstMessage(Address sender, long seqno) { if (log.isTraceEnabled()) log.trace(local_addr + " <-- SEND_FIRST_SEQNO(" + sender + "," + seqno + ")"); SenderEntry entry = send_table.get(sender); Table<Message> win = entry != null ? entry.sent_msgs : null; if (win == null) { if (log.isErrorEnabled()) log.error(local_addr + ": sender window for " + sender + " not found"); return; } boolean first_sent = false; for (long i = win.getLow() + 1; i <= seqno; i++) { Message rsp = win.get(i); if (rsp == null) continue; if (first_sent) { down_prot.down(new Event(Event.MSG, rsp)); } else { first_sent = true; // We need to copy the UnicastHeader and put it back into the message because Message.copy() // doesn't copy // the headers and therefore we'd modify the original message in the sender retransmission // window // (https://jira.jboss.org/jira/browse/JGRP-965) Message copy = rsp.copy(); Unicast2Header hdr = (Unicast2Header) copy.getHeader(this.id); Unicast2Header newhdr = hdr.copy(); newhdr.first = true; copy.putHeader(this.id, newhdr); down_prot.down(new Event(Event.MSG, copy)); } } }
public static String getAnnotations(Table table) { StringBuffer buf = new StringBuffer(); buf.append("{\n"); buf.append("\"annotations\": [\n"); int i = 1; int size = table.getAnnotations().size(); for (Annotation ann : table.getAnnotations()) { buf.append("{\n"); printJsonValue(buf, "name", ann.getType(), false); String values = ""; boolean first = true; for (String value : ann.getValues()) { if (!first) { values += ", "; first = false; } values += value; } printJsonValue(buf, "values", values, true); buf.append("}\n"); if (i != size) { buf.append(","); } i++; } buf.append("]\n"); buf.append("}\n"); return buf.toString(); }
// Test compaction of hints column family. It shouldn't remove all columns on compaction. @Test public void testCompactionOfHintsCF() throws Exception { // prepare hints column family Table systemTable = Table.open("system"); ColumnFamilyStore hintStore = systemTable.getColumnFamilyStore(SystemTable.HINTS_CF); hintStore.clearUnsafe(); hintStore.metadata.gcGraceSeconds(36000); // 10 hours hintStore.setCompactionStrategyClass(SizeTieredCompactionStrategy.class.getCanonicalName()); hintStore.disableAutoCompaction(); // insert 1 hint RowMutation rm = new RowMutation(TABLE4, ByteBufferUtil.bytes(1)); rm.add( new QueryPath(STANDARD1_CF, null, ByteBufferUtil.bytes(String.valueOf(COLUMN1))), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); RowMutation.hintFor(rm, UUID.randomUUID()).apply(); // flush data to disk hintStore.forceBlockingFlush(); assertEquals(1, hintStore.getSSTables().size()); // submit compaction FBUtilities.waitOnFuture(HintedHandOffManager.instance.compact()); while (CompactionManager.instance.getPendingTasks() > 0 || CompactionManager.instance.getActiveCompactions() > 0) TimeUnit.SECONDS.sleep(1); // single row should not be removed because of gc_grace_seconds // is 10 hours and there are no any tombstones in sstable assertEquals(1, hintStore.getSSTables().size()); }
@Override public void addColumn(IndexColumn indexColumn) { Table indexTable = indexColumn.getColumn().getTable(); Integer indexTableDepth = indexTable.getDepth(); assert indexTableDepth != null; super.addColumn(indexColumn); GroupIndexHelper.actOnGroupIndexTables(this, indexColumn, GroupIndexHelper.ADD); // Add the table into our navigable map if needed. Confirm it's within the branch ParticipatingTable participatingTable = tablesByDepth.get(indexTableDepth); if (participatingTable == null) { Map.Entry<Integer, ParticipatingTable> rootwardEntry = tablesByDepth.floorEntry(indexTableDepth); Map.Entry<Integer, ParticipatingTable> leafwardEntry = tablesByDepth.ceilingEntry(indexTableDepth); checkIndexTableInBranchNew(indexColumn, indexTable, indexTableDepth, rootwardEntry, true); checkIndexTableInBranchNew(indexColumn, indexTable, indexTableDepth, leafwardEntry, false); participatingTable = new ParticipatingTable(indexTable); tablesByDepth.put(indexTableDepth, participatingTable); } else if (participatingTable.table != indexTable) { throw new BranchingGroupIndexException( indexColumn.getIndex().getIndexName().getName(), indexTable.getName(), participatingTable.table.getName()); } participatingTable.markInvolvedInIndex(indexColumn.getColumn()); }
/** * Add a table by itself. Add columns later. * * @param tableName */ public Table addTable(String tableName) { Table table = new AbstractTable(tableName); tables.add(table); tableItems.put(tableName, new TableItem(table, tableName)); table.addColumn(new Column("_id", Column.COLUMN_TYPE.INTEGER, true)); return table; }
private int enqueueToPlace() throws Exception { DistributionServer.logging("Philosoph-" + this.getIndex() + " enqueues."); Place minPlace = table.getPlace(distributedClient.getStartPlace()); DistributionServer.logging("Philosoph-" + this.getIndex() + " Has min place"); // Try enqueue local and get shortest queue for (Place place : table.getPlaces()) { if (place.tryEnqueue()) { System.out.println(this + " is enqueued at local place " + place.getIndex()); return place.getIndex(); } if (place.getQueueLength() < minPlace.getQueueLength()) { minPlace = place; } } DistributionServer.logging("Philosoph-" + this.getIndex() + " tried enqueue locally"); // Try enqueue remote List<Client> clients = distributedClient.getClients(); DistributionServer.logging("Philosoph-" + this.getIndex() + " has clinets"); for (Client client : clients) { int placeIndex = client.tryEnqueue(); if (placeIndex >= 0) { System.out.println(this + " is enqueued at remote place " + placeIndex); return placeIndex; } } DistributionServer.logging("Philosoph-" + this.getIndex() + " tried enqueue remote"); // Enqueue at local place with shortest queue minPlace.enqueue(); System.out.println(this + " is enqueued at local minPlace " + minPlace.getIndex()); return minPlace.getIndex(); }
public static String getEntityName(Class entity) { if (mappedName.get(entity) != null) { return mappedName.get(entity); } String name = null; Table table = (Table) entity.getAnnotation(Table.class); if (table != null && table.name() != null && !table.name().isEmpty()) { name = table.name(); } else { Entity entityAnnotation = (Entity) entity.getAnnotation(Entity.class); if (entityAnnotation != null && entityAnnotation.name() != null && !entityAnnotation.name().isEmpty()) { name = entityAnnotation.name(); } else { name = entity.getSimpleName(); } } mappedName.put(entity, name); return name; }
/** * Chooses certain query conditions and assigns a copy of them to this filter. The original * condition is set to Expression.TRUE once assigned. * * @param condition * @throws HsqlException */ void setConditions(Expression condition) throws HsqlException { setCondition(condition); if (filterIndex == null) { filterIndex = filterTable.getPrimaryIndex(); } if (filterIndex.getVisibleColumns() == 1 || eStart == null || eAnd == null || eStart.exprType != Expression.EQUAL) { return; } boolean[] check = filterTable.getNewColumnCheckList(); Expression[] expr = new Expression[check.length]; int colindex = eStart.getArg().getColumnNr(); check[colindex] = true; expr[colindex] = eStart.getArg2(); eAnd.getEquiJoinColumns(this, check, expr); if (ArrayUtil.containsAllTrueElements(check, filterIndex.colCheck)) { isMultiFindFirst = true; findFirstExpressions = expr; } }
private void createTable(Division main) throws WingException { // Get all our parameters String id = parameters.getParameter("versionID", null); Table table = main.addTable("version", 1, 1); Row header = table.addRow(Row.ROLE_HEADER); header.addCellContent(T_column1); header.addCellContent(T_column2); header.addCellContent(T_column3); header.addCellContent(T_column4); VersioningService versioningService = new DSpace().getSingletonService(VersioningService.class); Version version = versioningService.getVersion(context, Integer.parseInt(id)); Row row = table.addRow(); row.addCell().addContent(version.getVersionNumber()); row.addCell().addContent(version.getEperson().getEmail()); row.addCell().addContent(new DCDate(version.getVersionDate()).toString()); row.addCell().addContent(version.getSummary()); List fields = main.addList("fields", List.TYPE_FORM); Composite addComposite = fields.addItem().addComposite("summary"); addComposite.setLabel(T_column4); addComposite.addTextArea("summary"); }
public void cleanMetadata() { for (Table table : getTables()) { if (table != null) { table.cleanup(); } } }
@Override public List<Table> getTableList(UUID subscriptionId, String serviceName) throws AzureCmdException { String[] cmd = new String[] { "mobile", "table", "list", "--json", "-s", subscriptionId.toString(), serviceName }; String json = AzureCommandHelper.getInstance().consoleExec(cmd); CustomJsonSlurper slurper = new CustomJsonSlurper(); List<Map<String, String>> tempRes = (List<Map<String, String>>) slurper.parseText(json); List<Table> res = new ArrayList<Table>(); for (Map<String, String> item : tempRes) { Table t = new Table(); t.setName(item.get("name")); t.setSelfLink(item.get("selflink")); res.add(t); } return res; }
@Test public void testRemoveColumn() throws IOException, ExecutionException, InterruptedException { Table table = Table.open("Keyspace1"); ColumnFamilyStore store = table.getColumnFamilyStore("Standard1"); RowMutation rm; DecoratedKey dk = Util.dk("key1"); // add data rm = new RowMutation("Keyspace1", dk.key); rm.add( new QueryPath("Standard1", null, "Column1".getBytes()), "asdf".getBytes(), new TimestampClock(0)); rm.apply(); store.forceBlockingFlush(); // remove rm = new RowMutation("Keyspace1", dk.key); rm.delete(new QueryPath("Standard1", null, "Column1".getBytes()), new TimestampClock(1)); rm.apply(); ColumnFamily retrieved = store.getColumnFamily( QueryFilter.getNamesFilter(dk, new QueryPath("Standard1"), "Column1".getBytes())); assert retrieved.getColumn("Column1".getBytes()).isMarkedForDelete(); assertNull(Util.cloneAndRemoveDeleted(retrieved, Integer.MAX_VALUE)); assertNull( Util.cloneAndRemoveDeleted( store.getColumnFamily(QueryFilter.getIdentityFilter(dk, new QueryPath("Standard1"))), Integer.MAX_VALUE)); }
public void putBatch(Optional<List<Request>> putRequests, boolean optimize) { if (!valid) { Logger.error("CANNOT PUT! NO VALID CONNECTION"); return; } List<Put> puts = new ArrayList<>(); if (putRequests.isPresent() && !putRequests.get().isEmpty()) { String tableName = putRequests.get().get(0).table; putRequests .get() .forEach( pr -> pr.getPut() .ifPresent( p -> { if (optimize) { p.setDurability(Durability.SKIP_WAL); } puts.add(p); })); try { final Table table = connection.getTable(TableName.valueOf(tableName)); if (optimize && table instanceof HTable) { ((HTable) table).setAutoFlush(false, true); } table.put(puts); table.close(); } catch (IOException e) { e.printStackTrace(); } } }