<commit_before>/***********************************************************************
* Copyright (c) 2013-2016 Commonwealth Computer Research, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at
* http://www.opensource.org/licenses/apache2.0.php.
*************************************************************************/

package org.locationtech.geomesa.tools.status

import com.beust.jcommander.Parameters
import org.geotools.data.Query
import org.geotools.filter.text.ecql.ECQL
import org.locationtech.geomesa.index.conf.QueryHints
import org.locationtech.geomesa.index.geotools.GeoMesaDataStore
import org.locationtech.geomesa.index.utils.ExplainLogger
import org.locationtech.geomesa.tools._
import org.locationtech.geomesa.utils.index.IndexMode
import org.opengis.filter.Filter

trait ExplainCommand[DS <: GeoMesaDataStore[DS, _, _]] extends DataStoreCommand[DS] {

  override def params: ExplainParams

  override val name: String = "explain"

  override def execute(): Unit = withDataStore(explain)

  protected def explain(ds: DS): Unit = {
    val query = new Query(params.featureName, Option(params.cqlFilter).map(ECQL.toFilter).getOrElse(Filter.INCLUDE))
    Option(params.attributes).filterNot(_.isEmpty).foreach(query.setPropertyNames)
    params.loadIndex(ds, IndexMode.Read).foreach { index =>
      query.getHints.put(QueryHints.QUERY_INDEX, index)
      Command.user.debug(s"Using index ${index.identifier}")
    }
    ds.getQueryPlan(query, None, new ExplainLogger(Command.output))<commit_msg>GEOMESA-1655 Fix GeoMesa command line tools output (#1357)<commit_after>/***********************************************************************
* Copyright (c) 2013-2016 Commonwealth Computer Research, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at
* http://www.opensource.org/licenses/apache2.0.php.
*************************************************************************/

package org.locationtech.geomesa.tools.status

import com.beust.jcommander.Parameters
import org.geotools.data.Query
import org.geotools.filter.text.ecql.ECQL
import org.locationtech.geomesa.index.conf.QueryHints
import org.locationtech.geomesa.index.geotools.GeoMesaDataStore
import org.locationtech.geomesa.index.utils.ExplainString
import org.locationtech.geomesa.tools._
import org.locationtech.geomesa.utils.index.IndexMode
import org.opengis.filter.Filter

trait ExplainCommand[DS <: GeoMesaDataStore[DS, _, _]] extends DataStoreCommand[DS] {

  override def params: ExplainParams

  override val name: String = "explain"

  override def execute(): Unit = withDataStore(explain)

  protected def explain(ds: DS): Unit = {
    val query = new Query(params.featureName, Option(params.cqlFilter).map(ECQL.toFilter).getOrElse(Filter.INCLUDE))
    Option(params.attributes).filterNot(_.isEmpty).foreach(query.setPropertyNames)
    params.loadIndex(ds, IndexMode.Read).foreach { index =>
      query.getHints.put(QueryHints.QUERY_INDEX, index)
      Command.user.debug(s"Using index ${index.identifier}")
    }
    val explainString = new ExplainString()
    ds.getQueryPlan(query, None, explainString)
    Command.output.info(explainString.toString)
{'fraction_non_alphanumeric': 0.17831255436358365, 'fraction_numerical': 0.009278051609162076, 'mean_word_length': 5.764705882352941, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3025113', 'n_tokens_mistral': 1014, 'n_tokens_neox': 962, 'n_words': 210}