Search in sources :

Example 11 with Nullable

use of edu.umd.cs.findbugs.annotations.Nullable in project incubator-rya by apache.

the class RdfTestUtil method getSp.

/**
 * Fetch the {@link StatementPattern} from a SPARQL string.
 *
 * @param sparql - A SPARQL query that contains only a single Statement Patern. (not nul)
 * @return The {@link StatementPattern} that was in the query, if it could be found. Otherwise {@code null}
 * @throws Exception The statement pattern could not be found in the parsed SPARQL query.
 */
@Nullable
public static StatementPattern getSp(final String sparql) throws Exception {
    requireNonNull(sparql);
    final AtomicReference<StatementPattern> statementPattern = new AtomicReference<>();
    final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
    parsed.getTupleExpr().visitChildren(new QueryModelVisitorBase<Exception>() {

        @Override
        public void meet(final StatementPattern node) throws Exception {
            statementPattern.set(node);
        }
    });
    return statementPattern.get();
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AtomicReference(java.util.concurrent.atomic.AtomicReference) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 12 with Nullable

use of edu.umd.cs.findbugs.annotations.Nullable in project incubator-rya by apache.

the class RdfTestUtil method getProjection.

/**
 * Get the first {@link Projection} node from a SPARQL query.
 *
 * @param sparql - The query that contains a single Projection node.
 * @return The first {@link Projection} that is encountered.
 * @throws Exception The query could not be parsed.
 */
@Nullable
public static Projection getProjection(final String sparql) throws Exception {
    requireNonNull(sparql);
    final AtomicReference<Projection> projection = new AtomicReference<>();
    final ParsedQuery parsed = new SPARQLParser().parseQuery(sparql, null);
    parsed.getTupleExpr().visit(new QueryModelVisitorBase<Exception>() {

        @Override
        public void meet(final Projection node) throws Exception {
            projection.set(node);
        }
    });
    return projection.get();
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) AtomicReference(java.util.concurrent.atomic.AtomicReference) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 13 with Nullable

use of edu.umd.cs.findbugs.annotations.Nullable in project hbase by apache.

the class HBaseTestingUtil method findLastTableState.

@Nullable
public TableState findLastTableState(final TableName table) throws IOException {
    final AtomicReference<TableState> lastTableState = new AtomicReference<>(null);
    ClientMetaTableAccessor.Visitor visitor = new ClientMetaTableAccessor.Visitor() {

        @Override
        public boolean visit(Result r) throws IOException {
            if (!Arrays.equals(r.getRow(), table.getName())) {
                return false;
            }
            TableState state = CatalogFamilyFormat.getTableState(r);
            if (state != null) {
                lastTableState.set(state);
            }
            return true;
        }
    };
    MetaTableAccessor.scanMeta(getConnection(), null, null, ClientMetaTableAccessor.QueryType.TABLE, Integer.MAX_VALUE, visitor);
    return lastTableState.get();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TableState(org.apache.hadoop.hbase.client.TableState) Result(org.apache.hadoop.hbase.client.Result) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 14 with Nullable

use of edu.umd.cs.findbugs.annotations.Nullable in project hbase by apache.

the class MetaTableAccessor method getTableState.

/**
 * Fetch table state for given table from META table
 * @param conn connection to use
 * @param tableName table to fetch state for
 */
@Nullable
public static TableState getTableState(Connection conn, TableName tableName) throws IOException {
    if (tableName.equals(TableName.META_TABLE_NAME)) {
        return new TableState(tableName, TableState.State.ENABLED);
    }
    Table metaHTable = getMetaHTable(conn);
    Get get = new Get(tableName.getName()).addColumn(HConstants.TABLE_FAMILY, HConstants.TABLE_STATE_QUALIFIER);
    Result result = metaHTable.get(get);
    return CatalogFamilyFormat.getTableState(result);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) TableState(org.apache.hadoop.hbase.client.TableState) Result(org.apache.hadoop.hbase.client.Result) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 15 with Nullable

use of edu.umd.cs.findbugs.annotations.Nullable in project hbase by apache.

the class FSTableDescriptors method get.

/**
 * Get the current table descriptor for the given table, or null if none exists.
 * <p/>
 * Uses a local cache of the descriptor but still checks the filesystem on each call if
 * {@link #fsvisited} is not {@code true}, i.e, we haven't done a full scan yet, to see if a newer
 * file has been created since the cached one was read.
 */
@Override
@Nullable
public TableDescriptor get(TableName tableName) {
    invocations++;
    if (usecache) {
        // Look in cache of descriptors.
        TableDescriptor cachedtdm = this.cache.get(tableName);
        if (cachedtdm != null) {
            cachehits++;
            return cachedtdm;
        }
        // we do not need to go to fs any more
        if (fsvisited) {
            return null;
        }
    }
    TableDescriptor tdmt = null;
    try {
        tdmt = getTableDescriptorFromFs(fs, getTableDir(tableName), fsreadonly).map(Pair::getSecond).orElse(null);
    } catch (IOException ioe) {
        LOG.debug("Exception during readTableDecriptor. Current table name = " + tableName, ioe);
    }
    // last HTD written wins
    if (usecache && tdmt != null) {
        this.cache.put(tableName, tdmt);
    }
    return tdmt;
}
Also used : IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Aggregations

Nullable (edu.umd.cs.findbugs.annotations.Nullable)17 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 ParsedQuery (org.openrdf.query.parser.ParsedQuery)8 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)8 Result (org.apache.hadoop.hbase.client.Result)3 TableState (org.apache.hadoop.hbase.client.TableState)3 TerminalSize (org.apache.hadoop.hbase.hbtop.terminal.TerminalSize)3 MultiProjection (org.openrdf.query.algebra.MultiProjection)3 Filter (org.openrdf.query.algebra.Filter)2 Projection (org.openrdf.query.algebra.Projection)2 StatementPattern (org.openrdf.query.algebra.StatementPattern)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 SortedMap (java.util.SortedMap)1 Get (org.apache.hadoop.hbase.client.Get)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 Table (org.apache.hadoop.hbase.client.Table)1