Return statistics record value from given {@link IStatistic}

@param record key to retrieve
@param stats  statistic object
@return
439077
protected long getRecord(String record, IStatistic stats) {
    if (record == null || stats == null) {
      return 0;
    }
    IStatisticRecord statsRecord = stats.getRecordByName(record);
    if (statsRecord == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Warning: no record for {}, available: {}", record, Arrays.toString(stats.getRecords()));
      }
      return 0;
    }
    return statsRecord.getValueAsLong();
  }
1001992
public static byte[] toBytes(TBase<?, ?> record) throws TException {
        if (record == null) {
            return null;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        TTransport transport = new TIOStreamTransport(null, baos);
        TProtocol oProtocol = protocolFactory.getProtocol(transport);
        record.write(oProtocol);
        // baos.close();
        return baos.toByteArray();
    }
1267168
public int getRecordCount(Rec record)
    {
        int iRecordCount = 1;
        if ((this.getNodeType() == MessageRecordDesc.NON_UNIQUE_NODE)
            && (!this.isSingleDetail(record)))
                iRecordCount = Integer.MAX_VALUE;   // Until EOF
        return iRecordCount;
    }
349971
@Override
    public void map(GenericData.Record record,
                    AvroCollector<Pair<ByteBuffer, ByteBuffer>> collector,
                    Reporter reporter) throws IOException {

        byte[] keyBytes = null;
        byte[] valBytes = null;
        Object keyRecord = null;
        Object valRecord = null;
        try {
            keyRecord = record.get(keyField);
            valRecord = record.get(valField);
            keyBytes = keySerializer.toBytes(keyRecord);
            valBytes = valueSerializer.toBytes(valRecord);

            this.collectorWrapper.setCollector(collector);
            this.mapper.map(keyBytes, valBytes, this.collectorWrapper);

            recordCounter++;
        } catch (OutOfMemoryError oom) {
            logger.error(oomErrorMessage(reporter));
            if (keyBytes == null) {
                logger.error("keyRecord caused OOM!");
            } else {
                logger.error("keyRecord: " + keyRecord);
                logger.error("valRecord: " + (valBytes == null ? "caused OOM" : valRecord));
            }
            throw new VoldemortException(oomErrorMessage(reporter), oom);
        }
    }
694172
private int binarySearch(T record) {
		int low = 0;
		int high = this.boundaries.length - 1;
		typeComparator.extractKeys(record, keys, 0);

		while (low <= high) {
			final int mid = (low + high) >>> 1;
			final int result = compareKeys(flatComparators, keys, this.boundaries[mid]);

			if (result > 0) {
				low = mid + 1;
			} else if (result < 0) {
				high = mid - 1;
			} else {
				return mid;
			}
		}
		// key not found, but the low index is the target
		// bucket, since the boundaries are the upper bound
		return low;
	}
378909
public StatisticImpl getStatistic() {
        if (enabled) {
            if (proxy == null) {
                System.out.println("[SpdStatisticExternal] null proxy");
                return null;
            }

            proxy.updateStatisticOnRequest(dataId);

            // onReqStatistic will be updated by the component
            // the reference is kept in this class
            return onReqStatistic;
        } else
            return null;
    }
1062641
@Override
    public void processRecord(Record record) {
        int thisRow = -1;
        int thisColumn = -1;
        String thisStr = null;

        switch (record.getSid()) {
            case BOFRecord.sid:
                BOFRecord br = (BOFRecord) record;
                if (br.getType() == BOFRecord.TYPE_WORKSHEET) {
                    // Create sub workbook if required
                    if (workbookBuildingListener != null && stubWorkbook == null) {
                        stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
                    }

                    //到这里证明已经是新的一个Sheet了,每开始一个新的Sheet则初始化一些数据
                    this.allSheetInExcel++;
                    this.currentSheetInExcel++;
                    this.currentRowInSheet = -1;
                    this.realRowInSheet = 0;
                }
                break;

            case SSTRecord.sid:
                sstRecord = (SSTRecord) record;
                break;

            case BlankRecord.sid:
                //空单元格
                BlankRecord brec = (BlankRecord) record;
                thisRow = brec.getRow();
                thisColumn = brec.getColumn();
                thisStr = null;
                break;
            case BoolErrRecord.sid:
                BoolErrRecord berec = (BoolErrRecord) record;

                thisRow = berec.getRow();
                thisColumn = berec.getColumn();
                thisStr = berec.isBoolean() ? String.valueOf(berec.getBooleanValue()) : "";
                break;

            case FormulaRecord.sid:
                FormulaRecord frec = (FormulaRecord) record;

                thisRow = frec.getRow();
                thisColumn = frec.getColumn();

                if (outputFormulaValues) {
                    if (Double.isNaN(frec.getValue())) {
                        // Formula result is a string
                        // This is stored in the next record
                        outputNextStringRecord = true;
                        nextRow = frec.getRow();
                        nextColumn = frec.getColumn();
                    } else {
                        thisStr = formatListener.formatNumberDateCell(frec);
                    }
                } else {
                    thisStr =
                            HSSFFormulaParser.toFormulaString(stubWorkbook, frec.getParsedExpression());
                }
                break;
            case StringRecord.sid:
                if (outputNextStringRecord) {
                    // String for formula
                    StringRecord srec = (StringRecord) record;
                    thisStr = srec.getString();
                    thisRow = nextRow;
                    thisColumn = nextColumn;
                    outputNextStringRecord = false;
                }
                break;

            case LabelRecord.sid:
                LabelRecord lrec = (LabelRecord) record;

                thisRow = lrec.getRow();
                thisColumn = lrec.getColumn();
                thisStr = lrec.getValue();
                break;
            case LabelSSTRecord.sid:
                LabelSSTRecord lsrec = (LabelSSTRecord) record;

                thisRow = lsrec.getRow();
                thisColumn = lsrec.getColumn();
                if (sstRecord == null) {
                    thisStr = null;
                } else {
                    thisStr = sstRecord.getString(lsrec.getSSTIndex()).toString();
                }
                break;
            case NoteRecord.sid:
                NoteRecord nrec = (NoteRecord) record;

                thisRow = nrec.getRow();
                thisColumn = nrec.getColumn();
                thisStr = null;
                break;
            case NumberRecord.sid:
                NumberRecord numrec = (NumberRecord) record;

                thisRow = numrec.getRow();
                thisColumn = numrec.getColumn();

                // Format
                thisStr = formatListener.formatNumberDateCell(numrec);
                break;
            case RKRecord.sid:
                RKRecord rkrec = (RKRecord) record;

                thisRow = rkrec.getRow();
                thisColumn = rkrec.getColumn();
                thisStr = null;
                break;
            default:
                break;
        }
        // Handle missing column
        if (record instanceof MissingCellDummyRecord) {
            MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
            thisRow = mc.getRow();
            thisColumn = mc.getColumn();
            thisStr = null;
        }
        // Handle new row
        if (thisRow != -1 && thisRow != lastRowNumber) {
            lastColumnNumber = -1;
            this.isNewRow = true;
            this.currentRowInSheet = thisRow;
            this.currentColInRow = -1;
            if (this.currentRowInSheet > 1) {
                //证明此行是数据行
                this.data = new HashMap<String, Object>();
            }
        }

        /******************************************************************************/
        /******************************************************************************/
        if (this.isNewRow) {
            this.isNewRow = false;
        }
        if (thisColumn > -1) {
            this.currentColInRow = thisColumn;
        }
        if (thisStr != null && !thisStr.isEmpty()) {
            if (this.currentRowInSheet == 0) {
                //标题行
                if (this.currentSheetInExcel == 0) {
                    //第0个Sheet则添加标题，0-based
                    this.titles.add(thisStr);
                }
            } else if (this.currentRowInSheet == 1) {
                //列名行
                if (this.currentSheetInExcel == 0) {
                    //第0个Sheet则添加列名，0-based
                    this.columns.add(thisStr);
                }

            } else {
                //数据行
                String key = this.columns.get(this.currentColInRow);
                Object value = this.getValue(thisStr);
                this.data.put(key, value);
            }
        }
        /******************************************************************************/
        // Update column and row count
        if (thisRow > -1) {
            lastRowNumber = thisRow;
        }
        if (thisColumn > -1) {
            lastColumnNumber = thisColumn;
        }

        // Handle end of row
        if (record instanceof LastCellOfRowDummyRecord) {
            // We're onto a new row
            lastColumnNumber = -1;
            /******************************************************************************/
            /******************************************************************************/
            if (this.currentRowInSheet > 1 && !this.data.isEmpty()) {
                //证明此行是数据行,且不为空行
                this.datas.add(this.data);
                this.realRowInSheet++;
                this.realRowInExcel++;
            }
            //判断用户是否开启限制
            if (this.limit > 0) {
                //开启限制
                if (this.datas.size() >= this.limit) {
                    if (this.callback != null) {
                        //若设置了回调函数则调用
                        try {
                            this.callback
                                    .callback(this.currentRowInSheet, this.currentSheetInExcel, this.realRowInSheet,
                                            this.realRowInExcel, this.allSheetInExcel, this.titles, this.columns,
                                            this.datas);
                        } catch (Exception e) {
                            throw new ReadExcelRuntimeException("SAX parser appears to be broken - " + e.getMessage());
                        }
                    }
                    //超过限制则清空
                    this.datas.clear();
                }
            }
            /******************************************************************************/
        }
    }
389060
protected byte[] getFieldAsBytes(GenericRecord record, String fieldLocation) throws Exception {
    Optional<Object> bytesValue = AvroUtils.getFieldValue(record, fieldLocation);
    if (!bytesValue.isPresent()) {
      throw new Exception("Bytes value with key " + fieldLocation + " not found in the record");
    }
    ByteBuffer bb = (ByteBuffer) bytesValue.get();
    if (bb.hasArray()) {
      return bb.array();
    } else {
      byte[] payloadBytes = new byte[bb.remaining()];
      bb.get(payloadBytes);
      return payloadBytes;
    }
  }
485810
private void exportToStatsD(List<Stat> stats) {
        // group stats by kafka group
        for (Stat stat : stats) {
            @SuppressWarnings("unchecked")
            Map<String, String> tags = (Map<String, String>) stat.get(Stat.STAT_KEYS.TAGS.getName());
            long value = Long.parseLong((String) stat.get(Stat.STAT_KEYS.VALUE.getName()));
            if (mConfig.getStatsdDogstatdsTagsEnabled()) {
                String metricName = (String) stat.get(Stat.STAT_KEYS.METRIC.getName());
                String[] tagArray = new String[tags.size()];
                int i = 0;
                for (Map.Entry<String, String> e : tags.entrySet()) {
                    tagArray[i++] = e.getKey() + ':' + e.getValue();
                }
                mStatsDClient.recordGaugeValue(metricName, value, tagArray);
            } else {
                StringBuilder builder = new StringBuilder();
                if (mConfig.getStatsDPrefixWithConsumerGroup()) {
                    builder.append(tags.get(Stat.STAT_KEYS.GROUP.getName()))
                            .append(PERIOD);
                }
                String metricName = builder
                        .append((String) stat.get(Stat.STAT_KEYS.METRIC.getName()))
                        .append(PERIOD)
                        .append(tags.get(Stat.STAT_KEYS.TOPIC.getName()))
                        .append(PERIOD)
                        .append(tags.get(Stat.STAT_KEYS.PARTITION.getName()))
                        .toString();
                mStatsDClient.recordGaugeValue(metricName, value);
            }
        }
    }
756637
public BaseTable doMakeTable(Record record)
    {
        if (((record.getDatabaseType() & DBConstants.TABLE_TYPE_MASK) == DBConstants.MEMORY)
            || ((record.getDatabaseType() & DBConstants.TABLE_TYPE_MASK) == DBConstants.UNSHAREABLE_MEMORY))
        {
        	BaseDatabase database = (BaseDatabase)this.getDatabaseOwner().getDatabase(DBParams.MEMORY, record.getDatabaseType(), null);
        	return database.doMakeTable(record);
        }
        else
            return null;
    }
1047109
public long getCounter(final String iStatName) {
    if (iStatName == null)
      return -1;

    // CHECK IF STATISTICS ARE ACTIVED
    if (recording < 0)
      return -1;

    synchronized (counters) {
      Long stat = counters.get(iStatName);

      if (stat == null)
        return -1;

      return stat.longValue();
    }
  }
803240
protected static function extract_grade_grade_from_record(stdClass $record, $ishistory = false) {
        $prefix = $ishistory ? 'ggh_' : 'gg_';
        $ggrecord = static::extract_record($record, $prefix);
        if ($ishistory) {
            // The grade history is not a real grade_grade so we remove the ID.
            $historyid = $ggrecord->id;
            unset($ggrecord->id);
        }
        $gg = new grade_grade($ggrecord, false);

        // There is a grade item in the record.
        if (!empty($record->gi_id)) {
            $gi = new grade_item(static::extract_record($record, 'gi_'), false);
            $gg->grade_item = $gi;  // This is a common hack throughout the grades API.
        }

        // Load the scale, when it still exists.
        if (!empty($gi->scaleid) && !empty($record->sc_id)) {
            $scalerec = static::extract_record($record, 'sc_');
            $gi->scale = new grade_scale($scalerec, false);
            $gi->scale->load_items();
        }

        if ($ishistory) {
            $gg->historyid = $historyid;
        }

        return $gg;
    }
587791
static <T> T maybeGet(Record record, TableField<Record, T> field, T defaultValue) {
    if (record.fieldsRow().indexOf(field) < 0) {
      return defaultValue;
    } else {
      T result = record.get(field);
      return result != null ? result : defaultValue;
    }
  }
230572
Record
parseRR(Tokenizer st, int classValue, long TTLValue)
throws IOException
{
	Name name = st.getName(zone);
	long ttl;
	int type;
	Record record;

	String s = st.getString();

	try {
		ttl = TTL.parseTTL(s);
		s = st.getString();
	}
	catch (NumberFormatException e) {
		ttl = TTLValue;
	}

	if (DClass.value(s) >= 0) {
		classValue = DClass.value(s);
		s = st.getString();
	}

	if ((type = Type.value(s)) < 0)
		throw new IOException("Invalid type: " + s);

	record = Record.fromString(name, type, classValue, ttl, st, zone);
	if (record != null)
		return (record);
	else
		throw new IOException("Parse error");
}
448232
private BaseTable getPhysicalTable(PassThruTable table, Record record)
    {
    	BaseTable altTable = table.getNextTable();
		if (altTable instanceof PassThruTable)
		{
			BaseTable physicalTable = getPhysicalTable((PassThruTable)altTable, record);
			if (physicalTable != null)
				if (physicalTable != altTable)
					return physicalTable;
		}
		else
			if (altTable.getDatabase().getDatabaseName(true).equals(record.getTable().getDatabase().getDatabaseName(true)))
				return altTable;
    	
    	Iterator<BaseTable> tables = table.getTables();
    	while (tables.hasNext())
    	{
    		altTable = tables.next();
    		if (altTable instanceof PassThruTable)
    		{
    			BaseTable physicalTable = getPhysicalTable((PassThruTable)altTable, record);
    			if (physicalTable != null)
    				if (physicalTable != altTable)
    					return physicalTable;
    		}
    		else 
    			if (altTable.getDatabase().getDatabaseName(true).equals(record.getTable().getDatabase().getDatabaseName(true)))
    				return altTable;
    	}
    	return table;
    }
768401
@SuppressWarnings("unchecked")
	public long addRecord(T record) throws IOException {

		if (recordsOutFile == null) {
			
			if (closed) {
				throw new IllegalStateException("The large record handler has been closed.");
			}
			if (recordsReader != null) {
				throw new IllegalStateException("The handler has already switched to sorting.");
			}
			
			LOG.debug("Initializing the large record spilling...");
			
			// initialize the utilities
			{
				final TypeComparator<?>[] keyComps = comparator.getFlatComparators();
				numKeyFields = keyComps.length;
				Object[] keyHolder = new Object[numKeyFields];
				
				comparator.extractKeys(record, keyHolder, 0);
				
				TypeSerializer<?>[] keySers = new TypeSerializer<?>[numKeyFields];
				TypeSerializer<?>[] tupleSers = new TypeSerializer<?>[numKeyFields + 1];
				
				int[] keyPos = new int[numKeyFields];
				
				for (int i = 0; i < numKeyFields; i++) {
					keyPos[i] = i;
					keySers[i] = createSerializer(keyHolder[i], i);
					tupleSers[i] = keySers[i];
				}
				// add the long serializer for the offset
				tupleSers[numKeyFields] = LongSerializer.INSTANCE;
				
				keySerializer = new TupleSerializer<Tuple>((Class<Tuple>) Tuple.getTupleClass(numKeyFields+1), tupleSers);
				keyComparator = new TupleComparator<Tuple>(keyPos, keyComps, keySers);
				
				keySerializerFactory = new RuntimeSerializerFactory<Tuple>(keySerializer, keySerializer.getTupleClass());

				keyTuple = keySerializer.createInstance();
			}
			
			// initialize the spilling
			final int totalNumSegments = memory.size();
			final int segmentsForKeys = (totalNumSegments >= 2*MAX_SEGMENTS_FOR_KEY_SPILLING) ? MAX_SEGMENTS_FOR_KEY_SPILLING : 
				Math.max(MIN_SEGMENTS_FOR_KEY_SPILLING, totalNumSegments - MAX_SEGMENTS_FOR_KEY_SPILLING);
				
			List<MemorySegment> recordsMemory = new ArrayList<MemorySegment>();
			List<MemorySegment> keysMemory = new ArrayList<MemorySegment>();
			
			for (int i = 0; i < segmentsForKeys; i++) {
				keysMemory.add(memory.get(i));
			}
			for (int i = segmentsForKeys; i < totalNumSegments; i++) {
				recordsMemory.add(memory.get(i));
			}
			
			recordsChannel = ioManager.createChannel();
			keysChannel = ioManager.createChannel();
			
			recordsOutFile = new FileChannelOutputView(
					ioManager.createBlockChannelWriter(recordsChannel), memManager,
					recordsMemory, memManager.getPageSize());
			
			keysOutFile = new FileChannelOutputView(
					ioManager.createBlockChannelWriter(keysChannel), memManager,
					keysMemory, memManager.getPageSize());
		}
		
		final long offset = recordsOutFile.getWriteOffset();
		if (offset < 0) {
			throw new RuntimeException("wrong offset");
		}
		
		Object[] keyHolder = new Object[numKeyFields];
		
		comparator.extractKeys(record, keyHolder, 0);
		for (int i = 0; i < numKeyFields; i++) {
			keyTuple.setField(keyHolder[i], i);
		}
		keyTuple.setField(offset, numKeyFields);
		
		keySerializer.serialize(keyTuple, keysOutFile);
		serializer.serialize(record, recordsOutFile);
		
		recordCounter++;
		
		return offset;
	}
542439
public JKTableRecord getRecord(final int row) {
		if (row >= getRowCount()) {
			throw new IllegalStateException("Row : " + row + " is out of index");
		}
		return this.records.get(row);
	}