/**
   * 1.按照过滤条件读取数据<br>
   * 2.按照任务配置里设定的离散化方法,进行离散化<br>
   * 3.按照任务配置里的时间粒度,对数据进行聚合
   *
   * @param filterCondition 过滤条件
   * @param doAggregate 是否按时间对数据进行聚合
   * @param doDiscretize 是否考虑离散化
   * @return
   */
  private DataItems readInput(String filterCondition, boolean doAggregate, boolean doDiscretize) {
    String sqlStr =
        "SELECT 事件发生时间," + task.getMiningObject() + " " + "FROM " + conn.DB_TABLE + " WHERE ";
    if (task.getFilterCondition().length() > 0) sqlStr += task.getFilterCondition() + " AND ";
    if (filterCondition != null && filterCondition.length() > 0)
      sqlStr += filterCondition + " AND ";
    sqlStr += "1=1 ORDER BY 事件发生时间 asc"; // 按时间先后顺序读取数据
    conn.closeConn();
    ResultSet rs = conn.sqlQuery(sqlStr);
    if (rs == null) {
      return null;
    }
    ResultSetMetaData meta = null;
    int numRecords = 0;
    try {
      meta = rs.getMetaData();
      int numCols = meta.getColumnCount();
      data = new DataItems();
      while (rs.next()) {
        numRecords++;
        StringBuilder sb = new StringBuilder();
        for (int i = 2; i <= numCols; i++)
          if (rs.getString(i) != null) sb.append(rs.getString(i).trim() + ",");
        if (sb.length() > 0) {
          Date d = parseTime(rs.getString(1).trim());
          if (d != null) data.add1Data(d, sb.substring(0, sb.length() - 1));
          else System.out.println("");
        }
      }
      rs.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    System.out.println("共" + numRecords + "条记录!");
    System.out.println("读取完毕:" + data.getLength() + "条记录!");

    boolean isNonDouble = !data.isAllDataIsDouble();
    // 先进行时间粒度上的聚合
    if (doAggregate)
      data =
          DataPretreatment.aggregateData(
              data, task.getGranularity(), task.getAggregateMethod(), isNonDouble);
    // 再进行离散化(只有数值型才能够离散化,否则应该会报错!)
    if (doDiscretize)
      data =
          DataPretreatment.toDiscreteNumbers(
              data,
              task.getDiscreteMethod(),
              task.getDiscreteDimension(),
              task.getDiscreteEndNodes());
    data.setGranularity(task.getGranularity()); // 设置数据的一些参数,如粒度
    String endNodes = data.discreteNodes();
    task.setDiscreteEndNodes(endNodes);
    return data;
  }
 public DataInputUtils(TaskElement task) {
   this.task = task;
   if (task.getDataSource().equals("DataBase")) {
     conn = new OracleUtils();
     if (!conn.tryConnect()) UtilsUI.showErrMsg("数据库无法连接!");
   }
 }
  public OracleFKHandler(WbConnection conn) {
    super(conn);
    currentUser = conn.getCurrentUser();
    containsStatusCol = true;

    // This is essentially a copy of the Statement used by the Oracle driver
    // the driver does not take unique constraints into account, and this statement does.
    // Otherwise foreign keys referencing unique constraints (rather than primary keys) would
    // not be displayed (DbExplorer, WbSchemaReport) or correctly processed (TableDependency)
    baseSql =
        "-- SQLWorkbench \n"
            + "SELECT "
            + OracleUtils.getCacheHint()
            + " NULL AS pktable_cat, \n"
            + "       p.owner AS pktable_schem, \n"
            + "       p.table_name AS pktable_name, \n"
            + "       pc.column_name AS pkcolumn_name, \n"
            + "       NULL AS fktable_cat, \n"
            + "       f.owner AS fktable_schem, \n"
            + "       f.table_name AS fktable_name, \n"
            + "       fc.column_name AS fkcolumn_name, \n"
            + "       fc.position AS key_seq, \n"
            + "       3 AS update_rule, \n"
            + "       decode (f.delete_rule, \n"
            + "              'CASCADE', 0, \n"
            + "              'SET NULL', 2, \n"
            + "              1 \n"
            + "       ) AS delete_rule, \n"
            + "       f.constraint_name AS fk_name, \n"
            + "       p.constraint_name AS pk_name, \n"
            + "       decode(f.deferrable, \n"
            + "             'DEFERRABLE', decode(f.deferred, 'IMMEDIATE', "
            + DatabaseMetaData.importedKeyInitiallyImmediate
            + ", "
            + DatabaseMetaData.importedKeyInitiallyDeferred
            + ") , \n"
            + "             'NOT DEFERRABLE',"
            + DatabaseMetaData.importedKeyNotDeferrable
            + " \n"
            + "       ) deferrability, \n"
            + "       case when f.status = 'ENABLED' then 'YES' else 'NO' end as enabled, \n"
            + "       case when f.validated = 'VALIDATED' then 'YES' else 'NO' end as validated \n "
            + "FROM all_cons_columns pc, \n"
            + "     all_constraints p, \n"
            + "     all_cons_columns fc, \n"
            + "     all_constraints f \n"
            + "WHERE f.constraint_type = 'R'  \n"
            + "AND p.owner = f.r_owner  \n"
            + "AND p.constraint_name = f.r_constraint_name  \n"
            + "AND p.constraint_type IN  ('P', 'U') \n"
            + // this is the difference to the original statement from the Oracle driver (it uses =
              // 'P')
            "AND pc.owner = p.owner  \n"
            + "AND pc.constraint_name = p.constraint_name  \n"
            + "AND pc.table_name = p.table_name  \n"
            + "AND fc.owner = f.owner  \n"
            + "AND fc.constraint_name = f.constraint_name  \n"
            + "AND fc.table_name = f.table_name  \n"
            + "AND fc.position = pc.position \n";
  }
 /**
  * Adjust the baseSql query to reflect if a table for the current user is queried.
  *
  * <p>If the table belongs to the current user, the user_XXX views can be used instead of the
  * all_XXX views. Using the user_XXX views is faster (at least on my system) than the all_XXX
  * views - although it is still an awfully slow statement... <br>
  * Querying user_constraints instead of all_constraints means that constraints between two schemas
  * will not be shown. In order to still enable this, the config property: <br>
  * <code>workbench.db.oracle.optimize_fk_query</code> <br>
  * can be set to false, if all_constraints should always be queried.
  *
  * @param tbl the table for which the query should be generated
  * @return the query to use
  * @see OracleUtils#optimizeCatalogQueries()
  */
 private String getQuery(TableIdentifier tbl) {
   if (OracleUtils.optimizeCatalogQueries()) {
     String schema = tbl.getRawSchema();
     if (StringUtil.isEmptyString(schema) || schema.equalsIgnoreCase(currentUser)) {
       return baseSql.replace(" all_c", " user_c");
     }
   }
   return baseSql;
 }
  /**
   * Get the Operators applicable for Connective Constraints
   *
   * @param factType
   * @param fieldName
   * @return
   */
  @Override
  public void getConnectiveOperatorCompletions(
      final String factType, final String fieldName, final Callback<String[]> callback) {
    final String fieldType = getFieldType(factType, fieldName);

    if (fieldType == null) {
      callback.callback(OperatorsOracle.STANDARD_CONNECTIVES);
      return;

    } else if (fieldName.equals(DataType.TYPE_THIS)) {
      isFactTypeAnEvent(
          factType,
          new Callback<Boolean>() {
            @Override
            public void callback(final Boolean isFactTypeAnEvent) {
              if (Boolean.TRUE.equals(isFactTypeAnEvent)) {
                callback.callback(
                    OracleUtils.joinArrays(
                        OperatorsOracle.STANDARD_CONNECTIVES,
                        OperatorsOracle.SIMPLE_CEP_CONNECTIVES,
                        OperatorsOracle.COMPLEX_CEP_CONNECTIVES));
                return;
              } else {
                callback.callback(OperatorsOracle.STANDARD_CONNECTIVES);
                return;
              }
            }
          });
    } else if (fieldType.equals(DataType.TYPE_STRING)) {
      callback.callback(OperatorsOracle.STRING_CONNECTIVES);
      return;

    } else if (DataType.isNumeric(fieldType)) {
      callback.callback(OperatorsOracle.COMPARABLE_CONNECTIVES);
      return;

    } else if (fieldType.equals(DataType.TYPE_DATE)) {
      callback.callback(
          OracleUtils.joinArrays(
              OperatorsOracle.COMPARABLE_CONNECTIVES, OperatorsOracle.SIMPLE_CEP_CONNECTIVES));
      return;

    } else if (fieldType.equals(DataType.TYPE_COMPARABLE)) {
      callback.callback(OperatorsOracle.COMPARABLE_CONNECTIVES);
      return;

    } else if (fieldType.equals(DataType.TYPE_COLLECTION)) {
      callback.callback(OperatorsOracle.COLLECTION_CONNECTIVES);
      return;

    } else {
      callback.callback(OperatorsOracle.STANDARD_CONNECTIVES);
    }
  }
 @Override
 public String[] getGlobalCollections() {
   final List<String> globalCollections = new ArrayList<String>();
   for (Map.Entry<String, String> e : filteredGlobalTypes.entrySet()) {
     if (filteredCollectionTypes.containsKey(e.getValue())) {
       if (Boolean.TRUE.equals(filteredCollectionTypes.get(e.getValue()))) {
         globalCollections.add(e.getKey());
       }
     }
   }
   return OracleUtils.toStringArray(globalCollections);
 }
 @Override
 public String[] getGlobalVariables() {
   return OracleUtils.toStringArray(filteredGlobalTypes.keySet());
 }