Esempio n. 1
0
  /** @hide */
  public <T> T fetchEntry(int entryId, QueryEvaluator<T> qe, T defaultResult, Object... params) {
    Cursor cursor = null;

    try {
      cursor = query(getFieldNames(), "entry=" + entryId);
      if (cursor != null) return qe.evaluate(cursor, defaultResult, params);
    } catch (SQLiteException ex) {
    } finally {
      if (cursor != null) cursor.close();
    }

    return defaultResult;
  }
Esempio n. 2
0
  /** @hide */
  public <T> T rawQuery(
      String sql, String[] selectionArgs, QueryEvaluator<T> qe, T defaultResult, Object... params) {
    Cursor cursor = null;

    try {
      cursor = rawQuery(sql, selectionArgs);
      if (cursor != null) return qe.evaluate(cursor, defaultResult, params);
    } catch (SQLiteException ex) {
    } finally {
      if (cursor != null) cursor.close();
    }

    return defaultResult;
  }
  /**
   * Specifies arguments accepted by all descendants from CommonCoreQueryEvaluator. When overriding
   * this, make sure to call super.setupArguments() and that defaultOptimization is set before you
   * do.
   */
  @Override
  public void setupArguments() {
    super.setupArguments();
    this.args.addEnumOption(
        "optimization",
        "Specify the optimization that should be applied",
        this.defaultOptimization);
    this.args.addEnumOption("join", "Specify the join algorithm to be used", JOIN.DEFAULT);
    this.args.addEnumOption(
        "optional", "Specify the join algorithm to be used in the optional operator", JOIN.DEFAULT);
    this.args.addEnumOption("sort", "Specify the sort algorithm to be used", SORT.DEFAULT);
    this.args.addEnumOption(
        "distinct", "Specify the distinct algorithm to be used", DISTINCT.DEFAULT);
    this.args.addEnumOption("result", "Specify the storage type of the result", QueryResult.type);
    this.args.addEnumOption(
        "codemap",
        "The type of map used for administrating the codes for values.",
        LiteralFactory.MapType.PREFIXCODEMAP);
    this.args.addEnumOption(
        "storage",
        "The type of storage used for all operators, indices and (intermediate) results.",
        STORAGE.MEMORY);
    this.args.addStringOption(
        "tmpdir",
        "The type of storage used for all operators, indices and (intermediate) results. You can also specify several temporary directories (separated by commas) in order to e.g. use several hard disks for performance reasons.",
        "");
    this.args.addEnumOption(
        "merge_join_optional",
        "Specifies if MergeJoinWithoutSorting, MergeJoinSort, MergeWithoutSortingOptional and MergeJoinOptional should be replaced by their parallel versions.",
        MERGE_JOIN_OPTIONAL.SEQUENTIAL);
    this.args.addStringOption(
        "paralleloperands",
        "specifies whether or not ParallelOperands are added as operands of joins in order to compute operand results in parallel. The string option can be \"NONE\" for do not add ParallelOperators, \"N\", where N is a number, which is used as size for the Bounded Queue (the default is used when N<=0), and \"lastN\" if only the last join should get ParallelOperators (N like before). Furthermore, if the the string starts with BLOCK, then the computed operand results are transmitted blockwise to the join/optional operator.",
        "NONE");
    this.args.addIntegerOption(
        "jointhreads",
        "specifies the number of threads to start for the parallel join operators...",
        ParallelJoin.getDEFAULT_NUMBER_THREADS());
    this.args.addIntegerOption(
        "joinbuffer",
        "specifies the maximum size for the buffer for the parallel join operators...",
        ParallelJoin.getMAXBUFFER());
    this.args.addEnumOption(
        "heap", "specifies the heap type to be used", SortConfiguration.getDEFAULT_HEAP_TYPE());
    this.args.addIntegerOption(
        "indexheap",
        "specifies the heap height used for index construction",
        SortConfiguration.getDEFAULT_HEIGHT());
    this.args.addEnumOption(
        "tosort",
        "specifies the tosort type to be used in heaps for the initial runs (if no heaps are used, i.e. tosort!=NONE)",
        SortConfiguration.getDEFAULT_TOSORT());
    this.args.addEnumOption(
        "mergeheaptype",
        "The heap type to be used for merging the initial runs for external merge sort.",
        SortConfiguration.getDEFAULT_MERGEHEAP_TYPE());
    this.args.addIntegerOption(
        "mergeheapheight",
        "The heap size to be used for merging the initial runs for external merge sort.",
        SortConfiguration.getDEFAULT_MERGE_HEAP_HEIGHT());

    this.args.addIntegerOption(
        "mergethreads",
        "specifies the number of threads to start for the merging phase of merge sort (=1 means sequential merging).",
        DBMergeSortedBag.getNumberOfThreads());
    this.args.addStringOption(
        "externalontology",
        "specifies an external ontology, which is used to optimize RDFS inference by replacing triple patterns adressing RDFS triple by concrete ones regarding the external ontology...",
        "");
    this.args.addIntegerOption(
        "chunk",
        "defines the chunk fraction of the data for SortedChunksHeap...",
        SortConfiguration.getDEFAULT_K());
    this.args.addIntegerOption(
        "yagomax",
        "specifies the maximum triples read by the YAGO parser (<=0 for all triples)...",
        YagoParser.getMaxTriples());
    this.args.addBooleanOption(
        "inmemoryexternalontologyinference",
        "specifies if the inference computations in external ontologies are done in memory (or disks are used for temporary data)",
        false);
    this.args.addStringOption(
        "encoding", "specifies the used encoding for reading in data files...", encoding);
  }
  @Override
  public void init() throws Exception {
    super.init();

    PARALLELOPERANDS parallelOperands;
    boolean blockwise = false;
    int limit = 0;

    String s = this.args.getString("paralleloperands").toUpperCase();
    if (s.compareTo("NONE") == 0) {
      parallelOperands = PARALLELOPERANDS.NONE;
    } else {
      if (s.startsWith("BLOCK")) {
        s = s.substring(5);
        blockwise = true;
      }
      if (s.startsWith("LAST")) {
        s = s.substring(4);
        parallelOperands = PARALLELOPERANDS.LAST;
      } else {
        parallelOperands = PARALLELOPERANDS.ALL;
      }
      try {
        limit = Integer.parseInt(s);
      } catch (final NumberFormatException nfe) {
        System.err.println(
            "An integer was expected as parameter of --paralleloperands instead of " + s + "!");
        System.err.println("The parameter will be ignored...");
      }
    }

    this.init(
        this.args.getString("type"),
        this.args.getString("externalontology"),
        this.args.getBool("inmemoryexternalontologyinference"),
        (RDFS) this.args.getEnum("rdfs"),
        (LiteralFactory.MapType) this.args.getEnum("codemap"),
        this.args.getString("tmpdir").split(","),
        this.args.get("loadindexinfo") != null,
        parallelOperands,
        blockwise,
        limit,
        this.args.getInt("jointhreads"),
        this.args.getInt("joinbuffer"),
        (Heap.HEAPTYPE) this.args.getEnum("heap"),
        (ToSort.TOSORT) this.args.getEnum("tosort"),
        this.args.getInt("indexheap"),
        this.args.getInt("mergeheapheight"),
        (Heap.HEAPTYPE) this.args.getEnum("mergeheaptype"),
        this.args.getInt("chunk"),
        this.args.getInt("mergethreads"),
        this.args.getInt("yagomax"),
        (QueryResult.TYPE) this.args.getEnum("result"),
        (STORAGE) this.args.getEnum("storage"),
        (JOIN) this.args.getEnum("join"),
        (JOIN) this.args.getEnum("optional"),
        (SORT) this.args.getEnum("sort"),
        (DISTINCT) this.args.getEnum("distinct"),
        (MERGE_JOIN_OPTIONAL) this.args.getEnum("merge_join_optional"),
        this.args.getString("encoding"));
  }
  public void run() {
    final ProgressWindow progressWindow = QueryManager.getProgressWindow();
    String status = null;
    boolean firstTimeWaiting = true;
    EvaluatorLoggingHandler.logger.info("listening for status updates");
    try {
      while (!this.finished) {
        // keep checking messages from the server until FINISHED,
        // FAILED or TIMEOUT is encountered
        try {
          while ((status = this.in.readLine()) != null) {
            switch (AnalysisInstruction.getFromName(status)) {
              case FAILED:
                // job failed
                this.completedState = QueryConstants.failedComplete;

                this.finish();
                break;
              case FINISHED:
                // job finished
                this.completedState = QueryConstants.successfulComplete;

                this.finish();
                break;
              case START:
                // jobs are queueing
                if (firstTimeWaiting) {
                  firstTimeWaiting = false;
                  status = "Queueing...";
                  progressWindow.setProgressBarText(status);
                }
                break;
              case STOP:
                break;
              case TIMEOUT:
                // job timed-out
                this.completedState = QueryConstants.timeoutComplete;

                this.finish();
                break;
              case UPDATE:
                final String nodeID = this.in.ready() ? this.in.readLine() : null;
                final String statusUpdate = this.in.ready() ? this.in.readLine() : null;
                if (nodeID != null && statusUpdate != null) {
                  QueryEvaluator.updateStatus(new NodeStatusUpdater(statusUpdate, nodeID));
                  EvaluatorLoggingHandler.logger.info(nodeID + " " + statusUpdate);
                } else {
                  EvaluatorLoggingHandler.logger.warning(
                      "Recieved instructions in unexpected order");
                }
                break;
              default:
                EvaluatorLoggingHandler.logger.info(status);
                progressWindow.setProgressBarText(status);
                break;
            }
          }
        } catch (final InterruptedIOException e) {
          EvaluatorLoggingHandler.logger.warning("read timed out, restarting..");
        } catch (final QueryAnalysisException e) {
          EvaluatorLoggingHandler.logger.log(Level.WARNING, "Couldn't update node status", e);
        }
      }
    } catch (final IOException e) {
      EvaluatorLoggingHandler.logger.log(Level.WARNING, "AnalysisListener interruped", e);
    } finally {
      EvaluatorLoggingHandler.logger.info(
          "Finished listening, " + this.completedState + ", " + status);
      progressWindow.setProgressBarText(this.completedState);
      QueryEvaluator.fillProgressBar();
      this.cleanUp();
    }
  }