Created
October 7, 2016 21:05
-
-
Save wemrysi/7ce4eb5467f934583fda7becb77a6044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2014–2016 SlamData Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package quasar.fs | |
import quasar.Predef._ | |
import quasar.Variables | |
import quasar.contrib.pathy.AFile | |
import quasar.main.FilesystemQueries | |
import quasar.sql.{Query, fixParser} | |
import pathy.Path._ | |
import scalaz._ | |
import scalaz.syntax.functor._ | |
import scalaz.syntax.show._ | |
class ExplainSpec | |
extends FileSystemTest[FileSystem]( | |
FileSystemTest.externalFsUT.map(_.map(ut => ut.contramapF(chroot.fileSystem[FileSystem](ut.testDir))))) | |
with quasar.sql.CompilerHelpers { | |
import FileSystemTest.oneDoc | |
val fsq = new FilesystemQueries[FileSystem] | |
val write = WriteFile.Ops[FileSystem] | |
val manage = ManageFile.Ops[FileSystem] | |
val dataFile: AFile = rootDir </> dir("explain") </> file("data") | |
val dataStr: String = posixCodec.printPath(dataFile) | |
def explainQuery(sql: String, fs: FileSystemUT[FileSystem]) = | |
s"QUERY: $sql" >> { | |
val parsedQuery = | |
fixParser.parse(Query(sql)) | |
.valueOr(err => throw new RuntimeException(err.shows)) | |
val result = | |
fsq.explainQuery(parsedQuery, Variables.empty, rootDir) | |
.run.run.run | |
fs.testInterpM(result).map { case (phases, disj) => | |
disj match { | |
case \/-(-\/(err)) => ko(err.shows).toResult | |
case -\/(err) => ko(err.shows).toResult | |
case \/-(\/-(_)) => pending("\n" + phases.map(_.shows).mkString("\n\n")) | |
} | |
}.unsafePerformSync | |
} | |
fileSystemShould { fs => | |
step(runT(fs.setupInterpM)(write.saveThese(dataFile, oneDoc).void).runVoid) | |
"Explain Queries" should { | |
//explainQuery(s"select * from `$dataStr`", fs) | |
//explainQuery(s"select * from `$dataStr` limit 10", fs) | |
//explainQuery(s"select city, pop from `$dataStr` limit 10", fs) | |
//explainQuery(s"select city, loc[0] from `$dataStr`", fs) | |
//explainQuery(s"select count(*) from `$dataStr` limit 11", fs) | |
explainQuery(s"select sum(pop) from `$dataStr`", fs) | |
//explainQuery(s"select avg(pop) from `$dataStr` group by state", fs) | |
//explainQuery(s"select count(*) from `$dataStr` where pop > 1000", fs) | |
//explainQuery(s"select count(*) from `$dataStr` where pop < 1000 and length(city) < 8", fs) | |
//explainQuery(s"select length(loc) from `$dataStr`", fs) | |
//explainQuery(s"""select city, pop, date_part("dow", TO_TIMESTAMP(pop)) as test_ts from `$dataStr` where city = "SPRINGFIELD" offset 50 limit 10""", fs) | |
} | |
step(runT(fs.setupInterpM)(manage.delete(dataFile)).runVoid) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment