{"action":"created","comment":{"url":"https://api.github.com/repos/locationtech/geomesa/pulls/comments/66606259","id":66606259,"diff_hunk":"@@ -0,0 +1,304 @@\n+/***********************************************************************\n+* Copyright (c) 2013-2016 Commonwealth Computer Research, Inc.\n+* All rights reserved. This program and the accompanying materials\n+* are made available under the terms of the Apache License, Version 2.0\n+* which accompanies this distribution and is available at\n+* http://www.opensource.org/licenses/apache2.0.php.\n+*************************************************************************/\n+\n+package org.locationtech.geomesa.tools.accumulo.commands.stats\n+\n+import com.beust.jcommander.{JCommander, Parameter, Parameters}\n+import com.typesafe.scalalogging.LazyLogging\n+import com.vividsolutions.jts.geom.{Geometry, Point}\n+import org.geotools.filter.text.ecql.ECQL\n+import org.geotools.util.Converters\n+import org.locationtech.geomesa.accumulo.data.stats.GeoMesaStats\n+import org.locationtech.geomesa.tools.accumulo.commands.CommandWithCatalog\n+import org.locationtech.geomesa.tools.accumulo.commands.stats.StatsHistogramCommand.StatsHistogramParams\n+import org.locationtech.geomesa.utils.stats.{Histogram, MinMax, Stat}\n+import org.opengis.feature.simple.SimpleFeatureType\n+import org.opengis.filter.Filter\n+\n+import scala.io.StdIn\n+import scala.reflect.ClassTag\n+import scala.util.Try\n+\n+class StatsHistogramCommand(parent: JCommander) extends CommandWithCatalog(parent) with LazyLogging {\n+\n+  override val command = \"stats-histogram\"\n+  override val params = new StatsHistogramParams\n+\n+  override def execute(): Unit = {\n+    val sft = ds.getSchema(params.featureName)\n+    val attributes = StatsCommand.getAttributes(sft, params)\n+    val filter = Option(params.cqlFilter).map(ECQL.toFilter).getOrElse(Filter.INCLUDE)\n+    val bins = Option(params.bins).map(_.intValue)\n+\n+    val histograms = if (params.exact) {\n+      val bounds = scala.collection.mutable.Map.empty[String, (Any, Any)]\n+      attributes.foreach { attribute =>\n+        ds.stats.getStats[MinMax[Any]](sft, Seq(attribute)).headOption.foreach { b =>\n+          bounds.put(attribute, if (b.min == b.max) Histogram.buffer(b.min) else b.bounds)\n+        }\n+      }\n+\n+      if (bounds.size != attributes.size) {\n+        val noBounds = attributes.filterNot(bounds.contains)\n+        logger.warn(s\"Initial bounds are not available for attributes ${noBounds.mkString(\", \")}.\")\n+        var response: Integer = null\n+        println(\"\\nWould you like to:\\n\" +\n+                \"  1. Calculate bounds (may be slow)\\n\" +\n+                \"  2. Use default bounds (may be less accurate)\\n\" +\n+                \"  3. Manually enter bounds\\n\" +\n+                \"  4. Cancel operation\\n\")\n+        while (response == null) {\n+          val in = StdIn.readLine(\"Please enter the number of your choice: \")\n+          response = Try(in.toInt.asInstanceOf[Integer]).filter(r => r > 0 && r < 5).getOrElse(null)\n+          if (response == null) {\n+            logger.error(\"Invalid input. Please enter 1-4.\")\n+          }\n+        }\n+        if (response == 1) {\n+          logger.info(\"Running bounds query...\")\n+          ds.stats.runStats[MinMax[Any]](sft, Stat.SeqStat(noBounds.map(Stat.MinMax)), filter).foreach { mm =>\n+            bounds.put(sft.getDescriptor(mm.attribute).getLocalName, mm.bounds)\n+          }\n+        } else if (response == 2) {\n+          noBounds.foreach { attribute =>\n+            val ct = ClassTag[Any](sft.getDescriptor(attribute).getType.getBinding)\n+            bounds.put(attribute, GeoMesaStats.defaultBounds(ct.runtimeClass))\n+          }\n+        } else if (response == 3) {\n+          noBounds.foreach { attribute =>\n+            val ct = sft.getDescriptor(attribute).getType.getBinding\n+            var lower: Any = null\n+            var upper: Any = null\n+            while (lower == null) {\n+              lower = Converters.convert(StdIn.readLine(s\"Enter initial lower bound for '$attribute': \"), ct)\n+              if (lower == null) {\n+                logger.error(s\"Couldn't convert input to appropriate type: ${ct.getSimpleName}\")\n+              }\n+            }\n+            while (upper == null) {\n+              upper = Converters.convert(StdIn.readLine(s\"Enter initial upper bound for '$attribute': \"), ct)\n+              if (upper == null) {\n+                logger.error(s\"Couldn't convert input to appropriate type: ${ct.getSimpleName}\")\n+              }\n+            }\n+            if (lower == upper) {\n+              bounds.put(attribute, Histogram.buffer(lower))\n+            } else {\n+              bounds.put(attribute, (lower, upper))\n+            }\n+          }\n+        } else {\n+          return // cancel operation","path":"geomesa-tools/src/main/scala/org/locationtech/geomesa/tools/accumulo/commands/stats/StatsHistogramCommand.scala","position":null,"original_position":96,"commit_id":"3a3c5bd45f1faaad7d7d13b2e7852d2d995af0e7","original_commit_id":"c9b8009c84de5afc67d1d39b85bfce20bcd1c4f1","user":{"login":"elahrvivaz","id":7715322,"avatar_url":"https://avatars.githubusercontent.com/u/7715322?v=3","gravatar_id":"","url":"https://api.github.com/users/elahrvivaz","html_url":"https://github.com/elahrvivaz","followers_url":"https://api.github.com/users/elahrvivaz/followers","following_url":"https://api.github.com/users/elahrvivaz/following{/other_user}","gists_url":"https://api.github.com/users/elahrvivaz/gists{/gist_id}","starred_url":"https://api.github.com/users/elahrvivaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elahrvivaz/subscriptions","organizations_url":"https://api.github.com/users/elahrvivaz/orgs","repos_url":"https://api.github.com/users/elahrvivaz/repos","events_url":"https://api.github.com/users/elahrvivaz/events{/privacy}","received_events_url":"https://api.github.com/users/elahrvivaz/received_events","type":"User","site_admin":false},"body":"fixed.","created_at":"2016-06-10T12:41:02Z","updated_at":"2016-06-10T12:41:02Z","html_url":"https://github.com/locationtech/geomesa/pull/900#discussion_r66606259","pull_request_url":"https://api.github.com/repos/locationtech/geomesa/pulls/900","_links":{"self":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/comments/66606259"},"html":{"href":"https://github.com/locationtech/geomesa/pull/900#discussion_r66606259"},"pull_request":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/900"}}},"pull_request":{"url":"https://api.github.com/repos/locationtech/geomesa/pulls/900","id":71265810,"html_url":"https://github.com/locationtech/geomesa/pull/900","diff_url":"https://github.com/locationtech/geomesa/pull/900.diff","patch_url":"https://github.com/locationtech/geomesa/pull/900.patch","issue_url":"https://api.github.com/repos/locationtech/geomesa/issues/900","number":900,"state":"open","locked":false,"title":"GEOMESA-1182,GEOMESA-538 Stats-based query planning","user":{"login":"elahrvivaz","id":7715322,"avatar_url":"https://avatars.githubusercontent.com/u/7715322?v=3","gravatar_id":"","url":"https://api.github.com/users/elahrvivaz","html_url":"https://github.com/elahrvivaz","followers_url":"https://api.github.com/users/elahrvivaz/followers","following_url":"https://api.github.com/users/elahrvivaz/following{/other_user}","gists_url":"https://api.github.com/users/elahrvivaz/gists{/gist_id}","starred_url":"https://api.github.com/users/elahrvivaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elahrvivaz/subscriptions","organizations_url":"https://api.github.com/users/elahrvivaz/orgs","repos_url":"https://api.github.com/users/elahrvivaz/repos","events_url":"https://api.github.com/users/elahrvivaz/events{/privacy}","received_events_url":"https://api.github.com/users/elahrvivaz/received_events","type":"User","site_admin":false},"body":"~~Note: stacks on top of #895 and #896, please consider only the last commit(s).~~\r\n\r\n* Stats are gathered during ingestion, and can be run manually through the command-line tools\r\n* There are now two options for query planning - stats based or the old index priority based\r\n* Query planning can be controlled by:\r\n  * The query hint org.locationtech.geomesa.accumulo.index.QueryHints#COST_EVALUATION_KEY\r\n  * System property 'geomesa.query.cost.type' - either 'Stats' or 'Index'\r\n  * Hint takes priority, then system property, otherwise uses stats based planning\r\n\r\nSigned-off-by: Emilio Lahr-Vivaz <elahrvivaz@ccri.com>","created_at":"2016-05-24T18:03:33Z","updated_at":"2016-06-10T12:41:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"20b14375d51dbbd22326be6a1ba84de95b3f9049","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/locationtech/geomesa/pulls/900/commits","review_comments_url":"https://api.github.com/repos/locationtech/geomesa/pulls/900/comments","review_comment_url":"https://api.github.com/repos/locationtech/geomesa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/locationtech/geomesa/issues/900/comments","statuses_url":"https://api.github.com/repos/locationtech/geomesa/statuses/3a3c5bd45f1faaad7d7d13b2e7852d2d995af0e7","head":{"label":"elahrvivaz:fcr_stats_planning","ref":"fcr_stats_planning","sha":"3a3c5bd45f1faaad7d7d13b2e7852d2d995af0e7","user":{"login":"elahrvivaz","id":7715322,"avatar_url":"https://avatars.githubusercontent.com/u/7715322?v=3","gravatar_id":"","url":"https://api.github.com/users/elahrvivaz","html_url":"https://github.com/elahrvivaz","followers_url":"https://api.github.com/users/elahrvivaz/followers","following_url":"https://api.github.com/users/elahrvivaz/following{/other_user}","gists_url":"https://api.github.com/users/elahrvivaz/gists{/gist_id}","starred_url":"https://api.github.com/users/elahrvivaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elahrvivaz/subscriptions","organizations_url":"https://api.github.com/users/elahrvivaz/orgs","repos_url":"https://api.github.com/users/elahrvivaz/repos","events_url":"https://api.github.com/users/elahrvivaz/events{/privacy}","received_events_url":"https://api.github.com/users/elahrvivaz/received_events","type":"User","site_admin":false},"repo":{"id":20541167,"name":"geomesa","full_name":"elahrvivaz/geomesa","owner":{"login":"elahrvivaz","id":7715322,"avatar_url":"https://avatars.githubusercontent.com/u/7715322?v=3","gravatar_id":"","url":"https://api.github.com/users/elahrvivaz","html_url":"https://github.com/elahrvivaz","followers_url":"https://api.github.com/users/elahrvivaz/followers","following_url":"https://api.github.com/users/elahrvivaz/following{/other_user}","gists_url":"https://api.github.com/users/elahrvivaz/gists{/gist_id}","starred_url":"https://api.github.com/users/elahrvivaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elahrvivaz/subscriptions","organizations_url":"https://api.github.com/users/elahrvivaz/orgs","repos_url":"https://api.github.com/users/elahrvivaz/repos","events_url":"https://api.github.com/users/elahrvivaz/events{/privacy}","received_events_url":"https://api.github.com/users/elahrvivaz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/elahrvivaz/geomesa","description":"","fork":true,"url":"https://api.github.com/repos/elahrvivaz/geomesa","forks_url":"https://api.github.com/repos/elahrvivaz/geomesa/forks","keys_url":"https://api.github.com/repos/elahrvivaz/geomesa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elahrvivaz/geomesa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elahrvivaz/geomesa/teams","hooks_url":"https://api.github.com/repos/elahrvivaz/geomesa/hooks","issue_events_url":"https://api.github.com/repos/elahrvivaz/geomesa/issues/events{/number}","events_url":"https://api.github.com/repos/elahrvivaz/geomesa/events","assignees_url":"https://api.github.com/repos/elahrvivaz/geomesa/assignees{/user}","branches_url":"https://api.github.com/repos/elahrvivaz/geomesa/branches{/branch}","tags_url":"https://api.github.com/repos/elahrvivaz/geomesa/tags","blobs_url":"https://api.github.com/repos/elahrvivaz/geomesa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elahrvivaz/geomesa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elahrvivaz/geomesa/git/refs{/sha}","trees_url":"https://api.github.com/repos/elahrvivaz/geomesa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elahrvivaz/geomesa/statuses/{sha}","languages_url":"https://api.github.com/repos/elahrvivaz/geomesa/languages","stargazers_url":"https://api.github.com/repos/elahrvivaz/geomesa/stargazers","contributors_url":"https://api.github.com/repos/elahrvivaz/geomesa/contributors","subscribers_url":"https://api.github.com/repos/elahrvivaz/geomesa/subscribers","subscription_url":"https://api.github.com/repos/elahrvivaz/geomesa/subscription","commits_url":"https://api.github.com/repos/elahrvivaz/geomesa/commits{/sha}","git_commits_url":"https://api.github.com/repos/elahrvivaz/geomesa/git/commits{/sha}","comments_url":"https://api.github.com/repos/elahrvivaz/geomesa/comments{/number}","issue_comment_url":"https://api.github.com/repos/elahrvivaz/geomesa/issues/comments{/number}","contents_url":"https://api.github.com/repos/elahrvivaz/geomesa/contents/{+path}","compare_url":"https://api.github.com/repos/elahrvivaz/geomesa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elahrvivaz/geomesa/merges","archive_url":"https://api.github.com/repos/elahrvivaz/geomesa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elahrvivaz/geomesa/downloads","issues_url":"https://api.github.com/repos/elahrvivaz/geomesa/issues{/number}","pulls_url":"https://api.github.com/repos/elahrvivaz/geomesa/pulls{/number}","milestones_url":"https://api.github.com/repos/elahrvivaz/geomesa/milestones{/number}","notifications_url":"https://api.github.com/repos/elahrvivaz/geomesa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elahrvivaz/geomesa/labels{/name}","releases_url":"https://api.github.com/repos/elahrvivaz/geomesa/releases{/id}","deployments_url":"https://api.github.com/repos/elahrvivaz/geomesa/deployments","created_at":"2014-06-05T20:51:54Z","updated_at":"2016-02-15T21:22:52Z","pushed_at":"2016-06-10T12:40:54Z","git_url":"git://github.com/elahrvivaz/geomesa.git","ssh_url":"git@github.com:elahrvivaz/geomesa.git","clone_url":"https://github.com/elahrvivaz/geomesa.git","svn_url":"https://github.com/elahrvivaz/geomesa","homepage":null,"size":32901,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"locationtech:master","ref":"master","sha":"3740acf334f3a518b7481e0d292de3ae7a983fff","user":{"login":"locationtech","id":1991411,"avatar_url":"https://avatars.githubusercontent.com/u/1991411?v=3","gravatar_id":"","url":"https://api.github.com/users/locationtech","html_url":"https://github.com/locationtech","followers_url":"https://api.github.com/users/locationtech/followers","following_url":"https://api.github.com/users/locationtech/following{/other_user}","gists_url":"https://api.github.com/users/locationtech/gists{/gist_id}","starred_url":"https://api.github.com/users/locationtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/locationtech/subscriptions","organizations_url":"https://api.github.com/users/locationtech/orgs","repos_url":"https://api.github.com/users/locationtech/repos","events_url":"https://api.github.com/users/locationtech/events{/privacy}","received_events_url":"https://api.github.com/users/locationtech/received_events","type":"Organization","site_admin":false},"repo":{"id":13226069,"name":"geomesa","full_name":"locationtech/geomesa","owner":{"login":"locationtech","id":1991411,"avatar_url":"https://avatars.githubusercontent.com/u/1991411?v=3","gravatar_id":"","url":"https://api.github.com/users/locationtech","html_url":"https://github.com/locationtech","followers_url":"https://api.github.com/users/locationtech/followers","following_url":"https://api.github.com/users/locationtech/following{/other_user}","gists_url":"https://api.github.com/users/locationtech/gists{/gist_id}","starred_url":"https://api.github.com/users/locationtech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/locationtech/subscriptions","organizations_url":"https://api.github.com/users/locationtech/orgs","repos_url":"https://api.github.com/users/locationtech/repos","events_url":"https://api.github.com/users/locationtech/events{/privacy}","received_events_url":"https://api.github.com/users/locationtech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/locationtech/geomesa","description":"GeoMesa is a suite of tools for working with big geo-spatial data in a distributed fashion.","fork":false,"url":"https://api.github.com/repos/locationtech/geomesa","forks_url":"https://api.github.com/repos/locationtech/geomesa/forks","keys_url":"https://api.github.com/repos/locationtech/geomesa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/locationtech/geomesa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/locationtech/geomesa/teams","hooks_url":"https://api.github.com/repos/locationtech/geomesa/hooks","issue_events_url":"https://api.github.com/repos/locationtech/geomesa/issues/events{/number}","events_url":"https://api.github.com/repos/locationtech/geomesa/events","assignees_url":"https://api.github.com/repos/locationtech/geomesa/assignees{/user}","branches_url":"https://api.github.com/repos/locationtech/geomesa/branches{/branch}","tags_url":"https://api.github.com/repos/locationtech/geomesa/tags","blobs_url":"https://api.github.com/repos/locationtech/geomesa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/locationtech/geomesa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/locationtech/geomesa/git/refs{/sha}","trees_url":"https://api.github.com/repos/locationtech/geomesa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/locationtech/geomesa/statuses/{sha}","languages_url":"https://api.github.com/repos/locationtech/geomesa/languages","stargazers_url":"https://api.github.com/repos/locationtech/geomesa/stargazers","contributors_url":"https://api.github.com/repos/locationtech/geomesa/contributors","subscribers_url":"https://api.github.com/repos/locationtech/geomesa/subscribers","subscription_url":"https://api.github.com/repos/locationtech/geomesa/subscription","commits_url":"https://api.github.com/repos/locationtech/geomesa/commits{/sha}","git_commits_url":"https://api.github.com/repos/locationtech/geomesa/git/commits{/sha}","comments_url":"https://api.github.com/repos/locationtech/geomesa/comments{/number}","issue_comment_url":"https://api.github.com/repos/locationtech/geomesa/issues/comments{/number}","contents_url":"https://api.github.com/repos/locationtech/geomesa/contents/{+path}","compare_url":"https://api.github.com/repos/locationtech/geomesa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/locationtech/geomesa/merges","archive_url":"https://api.github.com/repos/locationtech/geomesa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/locationtech/geomesa/downloads","issues_url":"https://api.github.com/repos/locationtech/geomesa/issues{/number}","pulls_url":"https://api.github.com/repos/locationtech/geomesa/pulls{/number}","milestones_url":"https://api.github.com/repos/locationtech/geomesa/milestones{/number}","notifications_url":"https://api.github.com/repos/locationtech/geomesa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/locationtech/geomesa/labels{/name}","releases_url":"https://api.github.com/repos/locationtech/geomesa/releases{/id}","deployments_url":"https://api.github.com/repos/locationtech/geomesa/deployments","created_at":"2013-09-30T20:13:46Z","updated_at":"2016-06-08T02:53:49Z","pushed_at":"2016-06-10T12:40:55Z","git_url":"git://github.com/locationtech/geomesa.git","ssh_url":"git@github.com:locationtech/geomesa.git","clone_url":"https://github.com/locationtech/geomesa.git","svn_url":"https://github.com/locationtech/geomesa","homepage":"https://www.locationtech.org/projects/technology.geomesa","size":44340,"stargazers_count":177,"watchers_count":177,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":89,"mirror_url":null,"open_issues_count":4,"forks":89,"open_issues":4,"watchers":177,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/900"},"html":{"href":"https://github.com/locationtech/geomesa/pull/900"},"issue":{"href":"https://api.github.com/repos/locationtech/geomesa/issues/900"},"comments":{"href":"https://api.github.com/repos/locationtech/geomesa/issues/900/comments"},"review_comments":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/900/comments"},"review_comment":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/locationtech/geomesa/pulls/900/commits"},"statuses":{"href":"https://api.github.com/repos/locationtech/geomesa/statuses/3a3c5bd45f1faaad7d7d13b2e7852d2d995af0e7"}}}}
{"actor":{"display_login":"elahrvivaz"}}