Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2018-12-10 07:09:32 +0300
committerGitHub <noreply@github.com>2018-12-10 07:09:32 +0300
commit4d61d27f1a5faa4470a6831fa077733e3b8a208d (patch)
tree40a16032f0c363f68fef3bb9405f9a0a18f63b41 /core/Segment
parentd17db094235314248d6138bfdd8c13f6a919f3be (diff)
Autodiscover tables for segments w/ complex segment expressions (#13664)
* Support autodiscovering joins for segments that use complex segment expressions. * Add accessor for ArchiveProcessor::$archiveWriter so new processors can be created in Archivers. * Add unit and integration tests. * Make detection logic a bit smarter when handling backticks. * Add test for parseColumnsFromSqlExpr.
Diffstat (limited to 'core/Segment')
-rw-r--r--core/Segment/SegmentExpression.php21
1 files changed, 20 insertions, 1 deletions
diff --git a/core/Segment/SegmentExpression.php b/core/Segment/SegmentExpression.php
index ffade291be..a477187fd6 100644
--- a/core/Segment/SegmentExpression.php
+++ b/core/Segment/SegmentExpression.php
@@ -301,12 +301,31 @@ class SegmentExpression
}
}
- $this->checkFieldIsAvailable($field, $availableTables);
+ $columns = self::parseColumnsFromSqlExpr($field);
+ foreach ($columns as $column) {
+ $this->checkFieldIsAvailable($column, $availableTables);
+ }
return array($sqlExpression, $value);
}
/**
+ * @param string $field
+ * @return string[]
+ */
+ public static function parseColumnsFromSqlExpr($field)
+ {
+ preg_match_all('/\b`?([a-zA-Z0-9_]+`?\.`?[a-zA-Z0-9_`]+)`?\b/', $field, $matches);
+ $result = isset($matches[1]) ? $matches[1] : [];
+ $result = array_map(function ($item) {
+ return str_replace('`', '', $item);
+ }, $result);
+ $result = array_unique($result);
+ $result = array_values($result);
+ return $result;
+ }
+
+ /**
* Check whether the field is available
* If not, add it to the available tables
*