-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds the schema provider and schema validator * Improves the schema provider and validator * Adds tests for the schema provider and validator
- Loading branch information
Fede Fernández
authored
Aug 16, 2017
1 parent
fda39a7
commit 9cfe86e
Showing
16 changed files
with
491 additions
and
350 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* 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 freestyle.cassandra | ||
|
||
import troy.cql.ast.{DataDefinition, DataManipulation} | ||
|
||
package object schema { | ||
|
||
sealed abstract class SchemaError(msg: String, maybeCause: Option[Throwable] = None) | ||
extends RuntimeException(msg) { | ||
maybeCause foreach initCause | ||
} | ||
|
||
case class SchemaDefinitionProviderError(msg: String, maybeCause: Option[Throwable] = None) | ||
extends SchemaError(msg, maybeCause) | ||
|
||
case class SchemaValidatorError(msg: String, maybeCause: Option[Throwable] = None) | ||
extends SchemaError(msg, maybeCause) | ||
|
||
type SchemaDefinition = Seq[DataDefinition] | ||
type Statement = DataManipulation | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
core/src/main/scala/schema/provider/TroySchemaProvider.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* 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 freestyle.cassandra | ||
package schema.provider | ||
|
||
import freestyle.cassandra.schema._ | ||
import troy.cql.ast.CqlParser | ||
|
||
class TroySchemaProvider(cql: String) extends SchemaDefinitionProvider { | ||
|
||
override def schemaDefinition: Either[SchemaDefinitionProviderError, SchemaDefinition] = | ||
CqlParser.parseSchema(cql) match { | ||
case CqlParser.Success(res, _) => Right(res) | ||
case CqlParser.Failure(msg, next) => | ||
Left( | ||
SchemaDefinitionProviderError( | ||
s"Parse Failure: $msg, line = ${next.pos.line}, column = ${next.pos.column}")) | ||
case CqlParser.Error(msg, _) => Left(SchemaDefinitionProviderError(msg)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* 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 freestyle.cassandra | ||
package schema | ||
|
||
package object provider { | ||
|
||
trait SchemaDefinitionProvider { | ||
def schemaDefinition: Either[SchemaDefinitionProviderError, SchemaDefinition] | ||
} | ||
|
||
} |
Oops, something went wrong.