code
stringlengths
73
34.1k
label
stringclasses
1 value
static private int indexOfNthOccurrenceOfCharIn(String str, char ch, int n) { boolean inMiddleOfQuote = false; int index = -1, previousIndex = 0; for (int i=0; i < n; i++) { do { index = str.indexOf(ch, index+1); if (index < 0) { re...
java
protected VoltTable runDML(String dml, boolean transformDml) { String modifiedDml = (transformDml ? transformDML(dml) : dml); printTransformedSql(dml, modifiedDml); return super.runDML(modifiedDml); }
java
static int getClassCode(Class cla) { if (!cla.isPrimitive()) { return ArrayUtil.CLASS_CODE_OBJECT; } return classCodeMap.get(cla, -1); }
java
public static void clearArray(int type, Object data, int from, int to) { switch (type) { case ArrayUtil.CLASS_CODE_BYTE : { byte[] array = (byte[]) data; while (--to >= from) { array[to] = 0; } return; ...
java
public static void adjustArray(int type, Object array, int usedElements, int index, int count) { if (index >= usedElements) { return; } int newCount = usedElements + count; int source; int target; int size; if (cou...
java
public static void sortArray(int[] array) { boolean swapped; do { swapped = false; for (int i = 0; i < array.length - 1; i++) { if (array[i] > array[i + 1]) { int temp = array[i + 1]; array[i + 1] = array[i]; ...
java
public static int find(Object[] array, Object object) { for (int i = 0; i < array.length; i++) { if (array[i] == object) { // hadles both nulls return i; } if (object != null && object.equals(array[i])) { return i; ...
java
public static int findNot(int[] array, int value) { for (int i = 0; i < array.length; i++) { if (array[i] != value) { return i; } } return -1; }
java
public static boolean areEqualSets(int[] arra, int[] arrb) { return arra.length == arrb.length && ArrayUtil.haveEqualSets(arra, arrb, arra.length); }
java
public static boolean haveEqualArrays(int[] arra, int[] arrb, int count) { if (count > arra.length || count > arrb.length) { return false; } for (int j = 0; j < count; j++) { if (arra[j] != arrb[j]) { return false; } } return...
java
public static boolean haveEqualArrays(Object[] arra, Object[] arrb, int count) { if (count > arra.length || count > arrb.length) { return false; } for (int j = 0; j < count; j++) { if (arra[j] != arrb[j]) { if (a...
java
public static int countSameElements(byte[] arra, int start, byte[] arrb) { int k = 0; int limit = arra.length - start; if (limit > arrb.length) { limit = arrb.length; } for (int i = 0; i < limit; i++) { if (arra[i + start] == arrb[i]) { ...
java
public static int find(byte[] arra, int start, int limit, byte[] arrb) { int k = start; limit = limit - arrb.length + 1; int value = arrb[0]; for (; k < limit; k++) { if (arra[k] == value) { if (arrb.length == 1) { return k; ...
java
public static int find(byte[] arra, int start, int limit, int b, int c) { int k = 0; for (; k < limit; k++) { if (arra[k] == b || arra[k] == c) { return k; } } return -1; }
java
public static void intIndexesToBooleanArray(int[] arra, boolean[] arrb) { for (int i = 0; i < arra.length; i++) { if (arra[i] < arrb.length) { arrb[arra[i]] = true; } } }
java
public static boolean containsAllTrueElements(boolean[] arra, boolean[] arrb) { for (int i = 0; i < arra.length; i++) { if (arrb[i] && !arra[i]) { return false; } } return true; }
java
public static int countTrueElements(boolean[] arra) { int count = 0; for (int i = 0; i < arra.length; i++) { if (arra[i]) { count++; } } return count; }
java
public static boolean hasNull(Object[] array, int[] columnMap) { int count = columnMap.length; for (int i = 0; i < count; i++) { if (array[columnMap[i]] == null) { return true; } } return false; }
java
public static boolean containsAt(byte[] arra, int start, byte[] arrb) { return countSameElements(arra, start, arrb) == arrb.length; }
java
public static int countStartElementsAt(byte[] arra, int start, byte[] arrb) { int k = 0; mainloop: for (int i = start; i < arra.length; i++) { for (int j = 0; j < arrb.length; j++) { if (arra[i] == arrb[j]) { ...
java
public static int[] arraySlice(int[] source, int start, int count) { int[] slice = new int[count]; System.arraycopy(source, start, slice, 0, count); return slice; }
java
public static void fillArray(Object[] array, Object value) { int to = array.length; while (--to >= 0) { array[to] = value; } }
java
public static Object duplicateArray(Object source) { int size = Array.getLength(source); Object newarray = Array.newInstance(source.getClass().getComponentType(), size); System.arraycopy(source, 0, newarray, 0, size); return newarray; }
java
public static Object resizeArrayIfDifferent(Object source, int newsize) { int oldsize = Array.getLength(source); if (oldsize == newsize) { return source; } Object newarray = Array.newInstance(source.getClass().getComponentType(), newsize); if (oldsize ...
java
public static void copyAdjustArray(Object source, Object dest, Object addition, int colindex, int adjust) { int length = Array.getLength(source); if (colindex < 0) { System.arraycopy(source, 0, dest, 0, length); ...
java
private static ColumnInfo[] prependColumn(ColumnInfo firstColumn, ColumnInfo[] columns) { int allLen = 1 + columns.length; ColumnInfo[] allColumns = new ColumnInfo[allLen]; allColumns[0] = firstColumn; for (int i = 0; i < columns.length; i++) { allColumns[i+1] = columns[i]; ...
java
public final String getColumnName(int index) { assert(verifyTableInvariants()); if ((index < 0) || (index >= m_colCount)) { throw new IllegalArgumentException("Not a valid column index."); } // move to the start of the list of column names int pos = POS_COL_TYPES + m...
java
public final void addRow(Object... values) { assert(verifyTableInvariants()); if (m_readOnly) { throw new IllegalStateException("Table is read-only. Make a copy before changing."); } if (m_colCount == 0) { throw new IllegalStateException("Table has no columns defi...
java
public static String varbinaryToPrintableString(byte[] bin) { PureJavaCrc32 crc = new PureJavaCrc32(); StringBuilder sb = new StringBuilder(); sb.append("bin[crc:"); crc.update(bin); sb.append(crc.getValue()); sb.append(",value:0x"); String hex = Encoder.hexEncode...
java
@Override public String toJSONString() { JSONStringer js = new JSONStringer(); try { js.object(); // status code (1 byte) js.keySymbolValuePair(JSON_STATUS_KEY, getStatusCode()); // column schema js.key(JSON_SCHEMA_KEY).array(); ...
java
public static VoltTable fromJSONString(String json) throws JSONException, IOException { JSONObject jsonObj = new JSONObject(json); return fromJSONObject(jsonObj); }
java
VoltTable semiDeepCopy() { assert(verifyTableInvariants()); // share the immutable metadata if it's present for tests final VoltTable cloned = new VoltTable(m_extraMetadata); cloned.m_colCount = m_colCount; cloned.m_rowCount = m_rowCount; cloned.m_rowStart = m_rowStart; ...
java
public ColumnInfo[] getTableSchema() { ColumnInfo[] schema = new ColumnInfo[m_colCount]; for (int i = 0; i < m_colCount; i++) { ColumnInfo col = new ColumnInfo(getColumnName(i), getColumnType(i)); schema[i] = col; } return schema; }
java
@Override public void checkProcessorConfig(Properties properties) { String exportClientClass = properties.getProperty(EXPORT_TO_TYPE); Preconditions.checkNotNull(exportClientClass, "export to type is undefined or custom export plugin class missing."); try { final Class<?> client...
java
private long extractCommittedSpHandle(ExportRow row, long committedSeqNo) { long ret = 0; if (committedSeqNo == ExportDataSource.NULL_COMMITTED_SEQNO) { return ret; } // Get the rows's sequence number (3rd column) long seqNo = (long) row.values[2]; if (seqNo ...
java
public void processMaterializedViewWarnings(Database db, HashMap<Table, String> matViewMap) throws VoltCompilerException { for (Table table : db.getTables()) { for (MaterializedViewInfo mvInfo : table.getViews()) { for (Statement stmt : mvInfo.getFallbackquerystmts()) { ...
java
public static MaterializedViewInfo getMaterializedViewInfo(Table tbl) { MaterializedViewInfo mvInfo = null; Table source = tbl.getMaterializer(); if (source != null) { mvInfo = source.getViews().get(tbl.getTypeName()); } return mvInfo; }
java
public static long getFragmentIdForPlanHash(byte[] planHash) { Sha1Wrapper key = new Sha1Wrapper(planHash); FragInfo frag = null; synchronized (FragInfo.class) { frag = m_plansByHash.get(key); } assert(frag != null); return frag.fragId; }
java
public static String getStmtTextForPlanHash(byte[] planHash) { Sha1Wrapper key = new Sha1Wrapper(planHash); FragInfo frag = null; synchronized (FragInfo.class) { frag = m_plansByHash.get(key); } assert(frag != null); // SQL statement text is not stored in the ...
java
public static long loadOrAddRefPlanFragment(byte[] planHash, byte[] plan, String stmtText) { Sha1Wrapper key = new Sha1Wrapper(planHash); synchronized (FragInfo.class) { FragInfo frag = m_plansByHash.get(key); if (frag == null) { frag = new FragInfo(key, plan, m_n...
java
public static byte[] planForFragmentId(long fragmentId) { assert(fragmentId > 0); FragInfo frag = null; synchronized (FragInfo.class) { frag = m_plansById.get(fragmentId); } assert(frag != null); return frag.plan; }
java
public List<AbstractExpression> bindingToIndexedExpression( AbstractExpression expr) { // Defer the result construction for as long as possible on the // assumption that this function mostly gets applied to eliminate // negative cases. if (m_type != expr.m_type) { ...
java
public static void toJSONArrayFromSortList( JSONStringer stringer, List<AbstractExpression> sortExpressions, List<SortDirectionType> sortDirections) throws JSONException { stringer.key(SortMembers.SORT_COLUMNS); stringer.array(); int listSize = sortExpressions...
java
public static void loadSortListFromJSONArray( List<AbstractExpression> sortExpressions, List<SortDirectionType> sortDirections, JSONObject jobj) throws JSONException { if (jobj.has(SortMembers.SORT_COLUMNS)) { sortExpressions.clear(); if (sortDirection...
java
public static List<AbstractExpression> loadFromJSONArrayChild( List<AbstractExpression> starter, JSONObject parent, String label, StmtTableScan tableScan) throws JSONException { if (parent.isNull(label)) { return null; } JSONArray jarr...
java
public AbstractExpression replaceWithTVE( Map<AbstractExpression, Integer> aggTableIndexMap, Map<Integer, ParsedColInfo> indexToColumnMap) { Integer ii = aggTableIndexMap.get(this); if (ii != null) { ParsedColInfo col = indexToColumnMap.get(ii); TupleValue...
java
public boolean hasAnySubexpressionWithPredicate(SubexprFinderPredicate pred) { if (pred.matches(this)) { return true; } if (m_left != null && m_left.hasAnySubexpressionWithPredicate(pred)) { return true; } if (m_right != null && m_right.hasAnySubexpressi...
java
void refineOperandType(VoltType valueType) { if (m_valueType != VoltType.NUMERIC) { return; } if (valueType == VoltType.DECIMAL) { m_valueType = VoltType.DECIMAL; m_valueSize = VoltType.DECIMAL.getLengthInBytesForFixedTypes(); } else { ...
java
protected final void finalizeChildValueTypes() { if (m_left != null) { m_left.finalizeValueTypes(); updateContentDeterminismMessage(m_left.getContentDeterminismMessage()); } if (m_right != null) { m_right.finalizeValueTypes(); updateContentDetermin...
java
protected final void resolveChildrenForTable(Table table) { if (m_left != null) { m_left.resolveForTable(table); } if (m_right != null) { m_right.resolveForTable(table); } if (m_args != null) { for (AbstractExpression argument : m_args) { ...
java
public boolean isValidExprForIndexesAndMVs(StringBuffer msg, boolean isMV) { if (containsFunctionById(FunctionSQL.voltGetCurrentTimestampId())) { msg.append("cannot include the function NOW or CURRENT_TIMESTAMP."); return false; } else if (hasAnySubexpressionOfClass(AggregateExpr...
java
public static boolean validateExprsForIndexesAndMVs(List<AbstractExpression> checkList, StringBuffer msg, boolean isMV) { for (AbstractExpression expr : checkList) { if (!expr.isValidExprForIndexesAndMVs(msg, isMV)) { return false; } } return true; }
java
private boolean containsFunctionById(int functionId) { if (this instanceof AbstractValueExpression) { return false; } List<AbstractExpression> functionsList = findAllFunctionSubexpressions(); for (AbstractExpression funcExpr: functionsList) { assert(funcExpr inst...
java
public boolean isValueTypeIndexable(StringBuffer msg) { if (!m_valueType.isIndexable()) { msg.append("expression of type " + m_valueType.getName()); return false; } return true; }
java
public boolean isValueTypeUniqueIndexable(StringBuffer msg) { // This call to isValueTypeIndexable is needed because // all comparison, all conjunction, and some operator expressions // need to refine it to compensate for their false claims that // their value types (actually non-indexab...
java
public void findUnsafeOperatorsForDDL(UnsafeOperatorsForDDL ops) { if ( ! m_type.isSafeForDDL()) { ops.add(m_type.symbol()); } if (m_left != null) { m_left.findUnsafeOperatorsForDDL(ops); } if (m_right != null) { m_right.findUnsafeOperatorsForD...
java
public AbstractExpression getFirstArgument() { if (m_left != null) { assert(m_args == null); return m_left; } if (m_args != null && m_args.size() > 0) { assert(m_left == null && m_right == null); return m_args.get(0); } return null;...
java
public static byte[] getHashedPassword(ClientAuthScheme scheme, String password) { if (password == null) { return null; } MessageDigest md = null; try { md = MessageDigest.getInstance(ClientAuthScheme.getDigestScheme(scheme)); } catch (NoSuchAlgorithmExce...
java
public static Object[] getAuthenticatedConnection(String host, String username, byte[] hashedPassword, int port, final Subject subject, ClientAuthScheme scheme, ...
java
public JSONObject getJSONObjectForZK() throws JSONException { final JSONObject jsObj = new JSONObject(); jsObj.put(SnapshotUtil.JSON_PATH, m_path); jsObj.put(SnapshotUtil.JSON_PATH_TYPE, m_stype.toString()); jsObj.put(SnapshotUtil.JSON_NONCE, m_nonce); jsObj.put(SnapshotUtil....
java
public static DatabaseSizes getCatalogSizes(Database dbCatalog, boolean isXDCR) { DatabaseSizes dbSizes = new DatabaseSizes(); for (Table table: dbCatalog.getTables()) { dbSizes.addTable(getTableSize(table, isXDCR)); } return dbSizes; }
java
static public void main(String[] sa) throws IOException, TarMalformatException { if (sa.length < 1) { System.out.println(RB.singleton.getString(RB.TARGENERATOR_SYNTAX, DbBackup.class.getName())); System.exit(0); } TarGenerator generator = new Tar...
java
public static byte[] fileToBytes(File path) throws IOException { FileInputStream fin = new FileInputStream(path); byte[] buffer = new byte[(int) fin.getChannel().size()]; try { if (fin.read(buffer) == -1) { throw new IOException("File " + path.getAbsolutePath() + " is...
java
public VoltTable run(SystemProcedureExecutionContext ctx, String tableName, String columnName, String compStr, VoltTable parameter, long chunksize) { return nibbleDeleteCommon(ctx, tableName, ...
java
public byte[] read() throws IOException { if (m_exception.get() != null) { throw m_exception.get(); } byte bytes[] = null; if (m_activeConverters.get() == 0) { bytes = m_available.poll(); } else { try { bytes = m_available.take...
java
public boolean compileFromDDL(final String jarOutputPath, final String... ddlFilePaths) { if (ddlFilePaths.length == 0) { compilerLog.error("At least one DDL file is required."); return false; } List<VoltCompilerReader> ddlReaderList; try { ddlReaderLi...
java
public boolean compileDDLString(String ddl, String jarPath) { final File schemaFile = VoltProjectBuilder.writeStringToTempFile(ddl); schemaFile.deleteOnExit(); final String schemaPath = schemaFile.getPath(); return compileFromDDL(jarPath, schemaPath); }
java
public boolean compileEmptyCatalog(final String jarOutputPath) { // Use a special DDL reader to provide the contents. List<VoltCompilerReader> ddlReaderList = new ArrayList<>(1); ddlReaderList.add(new VoltCompilerStringReader("ddl.sql", m_emptyDDLComment)); // Seed it with the DDL so tha...
java
private void debugVerifyCatalog(InMemoryJarfile origJarFile, Catalog origCatalog) { final VoltCompiler autoGenCompiler = new VoltCompiler(m_isXDCR); // Make the new compiler use the original jarfile's classloader so it can // pull in the class files for procedures and imports autoGen...
java
private Catalog replayFailedCatalogRebuildUnderDebug( VoltCompiler autoGenCompiler, List<VoltCompilerReader> autogenReaderList, InMemoryJarfile autoGenJarOutput) { // Be sure to set RETRY_FAILED_CATALOG_REBUILD_UNDER_DEBUG = true to enable // this last ditch retry...
java
HashMap<String, byte[]> getExplainPlans(Catalog catalog) { HashMap<String, byte[]> retval = new HashMap<>(); Database db = getCatalogDatabase(m_catalog); assert(db != null); for (Procedure proc : db.getProcedures()) { for (Statement stmt : proc.getStatements()) { ...
java
private Catalog compileCatalogInternal( final VoltCompilerReader cannonicalDDLIfAny, final Catalog previousCatalogIfAny, final List<VoltCompilerReader> ddlReaderList, final InMemoryJarfile jarOutput) { m_catalog = new Catalog(); // Initialize the catal...
java
private void addExtraClasses(final InMemoryJarfile jarOutput) throws VoltCompilerException { List<String> addedClasses = new ArrayList<>(); for (String className : m_addedClasses) { /* * Only add the class if it isn't already in the output jar. * The jar will be p...
java
public List<String> harvestCapturedDetail() { List<String> harvested = m_capturedDiagnosticDetail; m_capturedDiagnosticDetail = null; return harvested; }
java
String getKeyPrefix(StatementPartitioning partitioning, DeterminismMode detMode, String joinOrder) { // no caching for inferred yet if (partitioning.isInferred()) { return null; } String joinOrderPrefix = "#"; if (joinOrder != null) { joinOrderPrefix += j...
java
Statement getCachedStatement(String keyPrefix, String sql) { String key = keyPrefix + sql; Statement candidate = m_previousCatalogStmts.get(key); if (candidate == null) { ++m_stmtCacheMisses; return null; } // check that no underlying tables have been mo...
java
public HashRangeExpressionBuilder put(Integer value1, Integer value2) { m_builder.put(value1, value2); return this; }
java
public HashRangeExpression build(Integer hashColumnIndex) { Map<Integer, Integer> ranges = m_builder.build(); HashRangeExpression predicate = new HashRangeExpression(); predicate.setRanges(ranges); predicate.setHashColumnIndex(hashColumnIndex); return predicate; }
java
@Override public OrderableTransaction poll() { OrderableTransaction retval = null; updateQueueState(); if (m_state == QueueState.UNBLOCKED) { retval = super.peek(); super.poll(); // not BLOCKED_EMPTY assert(retval != null); } re...
java
@Override public boolean add(OrderableTransaction txnState) { if (m_initiatorData.containsKey(txnState.initiatorHSId) == false) { return false; } boolean retval = super.add(txnState); // update the queue state if (retval) updateQueueState(); return retval;...
java
public long noteTransactionRecievedAndReturnLastSeen(long initiatorHSId, long txnId, long lastSafeTxnIdFromInitiator) { // System.out.printf("Site %d got heartbeat message from initiator %d with txnid/safeid: %d/%d\n", // m_siteId, initiatorSiteId, txnId, lastSafeTxnIdF...
java
public void gotFaultForInitiator(long initiatorId) { // calculate the next minimum transaction w/o our dead friend noteTransactionRecievedAndReturnLastSeen(initiatorId, Long.MAX_VALUE, DtxnConstants.DUMMY_LAST_SEEN_TXN_ID); // remove initiator from minimum. txnid scoreboard LastInitiato...
java
public int ensureInitiatorIsKnown(long initiatorId) { int newInitiatorCount = 0; if (m_initiatorData.get(initiatorId) == null) { m_initiatorData.put(initiatorId, new LastInitiatorData()); newInitiatorCount++; } return newInitiatorCount; }
java
public Long getNewestSafeTransactionForInitiator(Long initiatorId) { LastInitiatorData lid = m_initiatorData.get(initiatorId); if (lid == null) { return null; } return lid.m_lastSafeTxnId; }
java
public Long safeToRecover() { boolean safe = true; for (LastInitiatorData data : m_initiatorData.values()) { final long lastSeenTxnId = data.m_lastSeenTxnId; if (lastSeenTxnId == DtxnConstants.DUMMY_LAST_SEEN_TXN_ID) { safe = false; } } ...
java
public void unauthenticate(HttpServletRequest request) { if (HTTP_DONT_USE_SESSION) return; HttpSession session = request.getSession(false); if (session != null) { session.removeAttribute(AUTH_USER_SESSION_KEY); session.invalidate(); } }
java
public AuthenticationResult authenticate(HttpServletRequest request) { HttpSession session = null; AuthenticationResult authResult = null; if (!HTTP_DONT_USE_SESSION && !m_dontUseSession) { try { session = request.getSession(); if (session != null) { ...
java
public static FunctionSQL newSQLFunction(String token, CompileContext context) { int id = regularFuncMap.get(token, -1); if (id == -1) { id = valueFuncMap.get(token, -1); } if (id == -1) { return null; } FunctionSQL function = new F...
java
public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) { return dataTree.processTxn(hdr, txn); }
java
public Stat statNode(String path, ServerCnxn serverCnxn) throws KeeperException.NoNodeException { return dataTree.statNode(path, serverCnxn); }
java
public byte[] getData(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException { return dataTree.getData(path, stat, watcher); }
java
public void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher) { dataTree.setWatches(relativeZxid, dataWatches, existWatches, childWatches, watcher); }
java
public List<ACL> getACL(String path, Stat stat) throws NoNodeException { return dataTree.getACL(path, stat); }
java
public List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException { return dataTree.getChildren(path, stat, watcher); }
java
public SiteTasker take() throws InterruptedException { SiteTasker task = m_tasks.poll(); if (task == null) { m_starvationTracker.beginStarvation(); } else { m_queueDepthTracker.pollUpdate(task.getQueueOfferTime()); return task; } try { ...
java
public SiteTasker poll() { SiteTasker task = m_tasks.poll(); if (task != null) { m_queueDepthTracker.pollUpdate(task.getQueueOfferTime()); } return task; }
java
public static BufferedWriter newWriter(File file, Charset charset) throws FileNotFoundException { checkNotNull(file); checkNotNull(charset); return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); }
java
private static void write(CharSequence from, File to, Charset charset, boolean append) throws IOException { asCharSink(to, charset, modes(append)).write(from); }
java
public static void copy(File from, Charset charset, Appendable to) throws IOException { asCharSource(from, charset).copyTo(to); }
java
public static boolean equal(File file1, File file2) throws IOException { checkNotNull(file1); checkNotNull(file2); if (file1 == file2 || file1.equals(file2)) { return true; } /* * Some operating systems may return zero as the length for files denoting system-dependent * entities suc...
java