Query filters · Apache Druid()

  本篇文章为你整理了Query filters · Apache Druid()的详细内容,包含有 Query filters · Apache Druid,希望能帮助你了解 Query filters · Apache Druid。

  Query filters · Apache DruidTechnologyUse CasesPowered ByDocsCommunityApacheDownload›Native query componentsGetting startedIntroduction to Apache DruidQuickstartDockerSingle server deploymentClustered deploymentTutorialsLoading files nativelyLoad from Apache KafkaLoad from Apache HadoopQuerying dataRoll-upConfiguring data retentionUpdating existing dataCompacting segmentsDeleting dataWriting an ingestion specTransforming input dataKerberized HDFS deep storageDesignDesignSegmentsProcesses and serversDeep storageMetadata storageZooKeeperIngestionIngestionData formatsSchema design tipsData managementStream ingestionApache KafkaAmazon KinesisTranquilityBatch ingestionNative batchHadoop-basedTask referenceTroubleshooting FAQQueryingDruid SQLNative queriesQuery executionConceptsDatasourcesJoinsLookupsMulti-value dimensionsMultitenancyQuery cachingContext parametersNative query typesTimeseriesTopNGroupByScanSearchTimeBoundarySegmentMetadataDatasourceMetadataNative query componentsFiltersGranularitiesDimensionsAggregationsPost-aggregationsExpressionsHaving filters (groupBy)Sorting and limiting (groupBy)Sorting (topN)String comparatorsVirtual columnsSpatial filtersConfigurationConfiguration referenceExtensionsLoggingOperationsWeb consoleGetting started with Apache DruidBasic cluster tuningAPI referenceHigh availabilityRolling updatesRetaining or automatically dropping dataMetricsAlertsWorking with different versions of Apache HadoopHTTP compressionTLS supportPassword providersdump-segment toolreset-cluster toolinsert-segment-to-db toolpull-deps toolMiscLegacy Management UIsDeep storage migrationExport Metadata ToolMetadata MigrationSegment Size OptimizationContent for build.sbtDevelopmentDeveloping on DruidCreating extensionsJavaScript functionalityBuild from sourceVersioningExperimental featuresMiscPapersHiddenApache Druid vs ElasticsearchApache Druid vs. Key/Value Stores (HBase/Cassandra/OpenTSDB)Apache Druid vs KuduApache Druid vs RedshiftApache Druid vs SparkApache Druid vs SQL-on-HadoopAuthentication and AuthorizationBrokerCoordinator ProcessHistorical ProcessIndexer ProcessIndexing ServiceMiddleManager ProcessOverlord ProcessRouter ProcessPeonsApproximate Histogram aggregatorsApache AvroMicrosoft AzureBloom FilterDataSketches extensionDataSketches HLL Sketch moduleDataSketches Quantiles Sketch moduleDataSketches Theta Sketch moduleDataSketches Tuple Sketch moduleBasic SecurityKerberosCached Lookup ModuleApache Ranger SecurityGoogle Cloud StorageHDFSApache Kafka LookupsGlobally Cached LookupsMySQL Metadata StoreORC ExtensionDruid pac4j based Security extensionApache Parquet ExtensionPostgreSQL Metadata StoreProtobufS3-compatibleSimple SSLContext Provider ModuleStats aggregatorTest Stats AggregatorsAmbari Metrics EmitterApache CassandraRackspace Cloud FilesDistinctCount AggregatorGraphite EmitterInfluxDB Line Protocol ParserInfluxDB EmitterKafka EmitterMaterialized ViewMoment Sketches for Approximate Quantiles moduleMoving Average QueryOpenTSDB EmitterDruid Redis CacheMicrosoft SQLServerStatsD EmitterT-Digest Quantiles Sketch moduleThriftTimestamp Min/Max aggregatorsGCE ExtensionsAliyun OSSCardinality/HyperUnique aggregatorsSelectRealtime ProcessEditQuery filtersApache Druid supports two query languages: Druid SQL and native queries.

  This document describes the native

  language. For information about aggregators available in SQL, refer to the

  SQL documentation.

  A filter is a JSON object indicating which rows of data should be included in the computation for a query. It’s essentially the equivalent of the WHERE clause in SQL. Apache Druid supports the following types of filters.

  Note

  Filters are commonly applied on dimensions, but can be applied on aggregated metrics, for example, see filtered-aggregator and having-filters.

  Selector filter

  The simplest filter is a selector filter. The selector filter will match a specific dimension with a specific value. Selector filters can be used as the base filters for more complex Boolean expressions of filters.

  The grammar for a SELECTOR filter is as follows:

  

"filter": { "type": "selector", "dimension": dimension_string , "value": dimension_value_string }

 

  

 

  This is the equivalent of WHERE dimension_string = dimension_value_string .

  The selector filter supports the use of extraction functions, see Filtering with Extraction Functions for details.

  Column Comparison filter

  The column comparison filter is similar to the selector filter, but instead compares dimensions to each other. For example:

  

"filter": { "type": "columnComparison", "dimensions": [ dimension_a , dimension_b ] }

 

  

 

  This is the equivalent of WHERE dimension_a = dimension_b .

  dimensions is list of DimensionSpecs, making it possible to apply an extraction function if needed.

  Regular expression filter

  The regular expression filter is similar to the selector filter, but using regular expressions. It matches the specified dimension with the given pattern. The pattern can be any standard Java regular expression.

  

"filter": { "type": "regex", "dimension": dimension_string , "pattern": pattern_string }

 

  

 

  The regex filter supports the use of extraction functions, see Filtering with Extraction Functions for details.

  Logical expression filters

  AND

  The grammar for an AND filter is as follows:

  

"filter": { "type": "and", "fields": [ filter , filter , ...] }

 

  

 

  The filters in fields can be any other filter defined on this page.

  OR

  The grammar for an OR filter is as follows:

  

"filter": { "type": "or", "fields": [ filter , filter , ...] }

 

  

 

  The filters in fields can be any other filter defined on this page.

  NOT

  The grammar for a NOT filter is as follows:

  

"filter": { "type": "not", "field": filter }

 

  

 

  The filter specified at field can be any other filter defined on this page.

  JavaScript filter

  The JavaScript filter matches a dimension against the specified JavaScript function predicate. The filter matches values for which the function returns true.

  The function takes a single argument, the dimension value, and returns either true or false.

  

{

 

   "type" : "javascript",

   "dimension" : dimension_string ,

   "function" : "function(value) { ... }"

  

 

  Example

  The following matches any dimension values for the dimension name between bar and foo

  

{

 

   "type" : "javascript",

   "dimension" : "name",

   "function" : "function(x) { return(x = bar x = foo) }"

  

 

  The JavaScript filter supports the use of extraction functions, see Filtering with Extraction Functions for details.

  JavaScript-based functionality is disabled by default. Please refer to the Druid JavaScript programming guide for guidelines about using Druids JavaScript functionality, including instructions on how to enable it.

  Extraction filter

  The extraction filter is now deprecated. The selector filter with an extraction function specified

  provides identical functionality and should be used instead.

  Extraction filter matches a dimension using some specific Extraction function.

  The following filter matches the values for which the extraction function has transformation entry input_key=output_value where

  output_value is equal to the filter value and input_key is present as dimension.

  Example

  The following matches dimension values in [product_1, product_3, product_5] for the column product

  

{

 

   "filter": {

   "type": "extraction",

   "dimension": "product",

   "value": "bar_1",

   "extractionFn": {

   "type": "lookup",

   "lookup": {

   "type": "map",

   "map": {

   "product_1": "bar_1",

   "product_5": "bar_1",

   "product_3": "bar_1"

  

 

  Search filter

  Search filters can be used to filter on partial string matches.

  

{

 

   "filter": {

   "type": "search",

   "dimension": "product",

   "query": {

   "type": "insensitive_contains",

   "value": "foo"

  

 

  
typeThis String should always be search .yes

  dimensionThe dimension to perform the search over.yes

  queryA JSON object for the type of search. See below for more information.yes

  extractionFnExtraction function to apply to the dimensionno

  
typeThis String should always be contains .yes

  valueA String value to run the search over.yes

  caseSensitiveWhether two string should be compared as case sensitive or notno (default == false)

  
typeThis String should always be insensitive_contains .yes

  valueA String value to run the search over.yes

  
Note that an insensitive_contains search is equivalent to a contains search with caseSensitive : false (or not

  provided).

  Fragment

  
typeThis String should always be fragment .yes

  valuesA JSON array of String values to run the search over.yes

  caseSensitiveWhether strings should be compared as case sensitive or not. Default: false(insensitive)no

  
In filter

  In filter can be used to express the following SQL query:

  

 SELECT COUNT(*) AS Count FROM `table` WHERE `outlaw` IN (Good, Bad, Ugly)

 

  

 

  The grammar for a IN filter is as follows:

  

{

 

   "type": "in",

   "dimension": "outlaw",

   "values": ["Good", "Bad", "Ugly"]

  

 

  The IN filter supports the use of extraction functions, see Filtering with Extraction Functions for details.

  If an empty values array is passed to the IN filter, it will simply return an empty result.

  If the dimension is a multi-valued dimension, the IN filter will return true if one of the dimension values is

  in the values array.

  Like filter

  Like filters can be used for basic wildcard searches. They are equivalent to the SQL LIKE operator. Special characters

  supported are % (matches any number of characters) and _ (matches any one character).

  
dimensionStringThe dimension to filter onyes

  patternStringLIKE pattern, such as foo% or ___bar .yes

  escapeStringAn escape character that can be used to escape special characters.no

  extractionFnExtraction functionExtraction function to apply to the dimensionno

  
Like filters support the use of extraction functions, see Filtering with Extraction Functions for details.

  This Like filter expresses the condition last_name LIKE D% (i.e. last_name starts with D ).

  

{

 

   "type": "like",

   "dimension": "last_name",

   "pattern": "D%"

  

 

  Bound filter

  Bound filters can be used to filter on ranges of dimension values. It can be used for comparison filtering like

  greater than, less than, greater than or equal to, less than or equal to, and between (if both lower and

   upper are set).

  
dimensionStringThe dimension to filter onyes

  lowerStringThe lower bound for the filterno

  upperStringThe upper bound for the filterno

  lowerStrictBooleanPerform strict comparison on the lower bound ( instead of = )no, default: false

  upperStrictBooleanPerform strict comparison on the upper bound ( instead of = )no, default: false

  orderingStringSpecifies the sorting order to use when comparing values against the bound. Can be one of the following values: lexicographic , alphanumeric , numeric , strlen , version . See Sorting Orders for more details.no, default: lexicographic

  extractionFnExtraction functionExtraction function to apply to the dimensionno

  
Bound filters support the use of extraction functions, see Filtering with Extraction Functions for details.

  The following bound filter expresses the condition 21 = age = 31:

  

{

 

   "type": "bound",

   "dimension": "age",

   "lower": "21",

   "upper": "31" ,

   "ordering": "numeric"

  

 

  This filter expresses the condition foo = name = hoo, using the default lexicographic sorting order.

  

{

 

   "type": "bound",

   "dimension": "name",

   "lower": "foo",

   "upper": "hoo"

  

 

  Using strict bounds, this filter expresses the condition 21 age 31

  

{

 

   "type": "bound",

   "dimension": "age",

   "lower": "21",

   "lowerStrict": true,

   "upper": "31" ,

   "upperStrict": true,

   "ordering": "numeric"

  

 

  The user can also specify a one-sided bound by omitting upper or lower . This filter expresses age 31.

  

{

 

   "type": "bound",

   "dimension": "age",

   "upper": "31" ,

   "upperStrict": true,

   "ordering": "numeric"

  

 

  Likewise, this filter expresses age = 18

  

{

 

   "type": "bound",

   "dimension": "age",

   "lower": "18" ,

   "ordering": "numeric"

  

 

  Interval Filter

  The Interval filter enables range filtering on columns that contain long millisecond values, with the boundaries specified as ISO 8601 time intervals. It is suitable for the __time column, long metric columns, and dimensions with values that can be parsed as long milliseconds.

  This filter converts the ISO 8601 intervals to long millisecond start/end ranges and translates to an OR of Bound filters on those millisecond ranges, with numeric comparison. The Bound filters will have left-closed and right-open matching (i.e., start = time end).

  
typeStringThis should always be interval .yes

  dimensionStringThe dimension to filter onyes

  intervalsArrayA JSON array containing ISO-8601 interval strings. This defines the time ranges to filter on.yes

  extractionFnExtraction functionExtraction function to apply to the dimensionno

  以上就是Query filters · Apache Druid()的详细内容,想要了解更多 Query filters · Apache Druid的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: