public BTable(String tableName, BStructureType constraintType) { this.nextPrefetched = false; this.hasNextVal = false; this.tableProvider = null; this.tableName = tableName; this.constraintType = constraintType; this.type = new BTableType(constraintType); }
private static boolean checkIsTableType(BType sourceType, BTableType targetType, List<TypePair> unresolvedTypes) { if (sourceType.getTag() != TypeTags.TABLE_TAG) { return false; } return checkTableConstraints(((BTableType) sourceType).getConstrainedType(), targetType.getConstrainedType(), unresolvedTypes); }
public BTable(BType type, BValueArray indexColumns, BValueArray keyColumns, BValueArray dataRows) { //Create table with given constraints. BType constrainedType = ((BTableType) type).getConstrainedType(); this.tableProvider = TableProvider.getInstance(); this.tableName = tableProvider.createTable(constrainedType, keyColumns, indexColumns); this.constraintType = (BStructureType) constrainedType; this.type = new BTableType(constraintType); this.primaryKeys = keyColumns; this.indices = indexColumns; //Insert initial data if (dataRows != null) { insertInitialData(dataRows); } }
@Override public BValue copy(Map<BValue, BValue> refs) { if (tableClosed) { throw new BallerinaException("Trying to invoke clone built-in method over a closed table"); } if (isFrozen()) { return this; } if (refs.containsKey(this)) { return refs.get(this); } TableIterator cloneIterator = tableProvider.createIterator(this.tableName, this.constraintType); BValueArray data = new BValueArray(); int cursor = 0; try { while (cloneIterator.next()) { data.add(cursor++, cloneIterator.generateNext()); } BTable table = new BTable(new BTableType(constraintType), this.indices, this.primaryKeys, data); refs.put(this, table); return table; } finally { cloneIterator.close(); } }
@Override public BType getConstrainedType(char typeChar, BType constraint) { switch (typeChar) { case 'J': if (constraint == null) { return BTypes.typeJSON; } return new BJSONType(constraint); case 'D': if (constraint == null) { return BTypes.typeTable; } return new BTableType(constraint); case 'M': if (constraint == null || constraint == BTypes.typeAny) { return BTypes.typeMap; } return new BMapType(constraint); case 'H': return new BStreamType(constraint); case 'G': case 'T': case 'X': case 'Q': default: return constraint; } }
public BTable(String query, BTable fromTable, BTable joinTable, BStructureType constraintType, BValueArray params) { this.tableProvider = TableProvider.getInstance(); if (!fromTable.isInMemoryTable()) { throw new BallerinaException(BallerinaErrorReasons.TABLE_OPERATION_ERROR, "Table query over a cursor table not supported"); } if (joinTable != null) { if (!joinTable.isInMemoryTable()) { throw new BallerinaException(BallerinaErrorReasons.TABLE_OPERATION_ERROR, "Table query over a cursor table not supported"); } this.tableName = tableProvider.createTable(fromTable.tableName, joinTable.tableName, query, constraintType, params); } else { this.tableName = tableProvider.createTable(fromTable.tableName, query, constraintType, params); } this.constraintType = constraintType; this.type = new BTableType(constraintType); }