example QuickCSV
#This example is recommended for anyone dealing with CSV data and is built-in to the IDE as QuickCSV.
#It imports a set of cloud-based CSV files about land and water animals into CQL,
#demonstrates basic CQL operations, and then exports the data to a local CSV file.
#We use SQL types (String, Integer, etc).
# Our land and water schemas share a common overlap schema about amphibians,
# which we express using an import statement.
schema AmphibianSchema = literal : sql {
entities
Amphibian Animal
foreign_keys
toAnimal : Amphibian -> Animal
attributes
species : Animal -> String
}
schema LandSchema = literal : sql {
imports
AmphibianSchema
entities
LandAnimal
foreign_keys
isA : Amphibian -> LandAnimal
isA : LandAnimal -> Animal
path_equations
Amphibian.isA.isA = Amphibian.toAnimal
}
schema WaterSchema = literal : sql {
imports
AmphibianSchema
entities
WaterAnimal
foreign_keys
isA : Amphibian -> WaterAnimal
isA : WaterAnimal -> Animal
path_equations
Amphibian.isA.isA = Amphibian.toAnimal
}
#Next, we import data from the internet. CQL expects one file per entity, with one column
#per foreign key or attribute. There are many options, such as providing a column to column
#name mapping during import, or to generate missing fields, etc; for details, see the built-in
#CSV example.
instance LandInstance = import_csv "http://categoricaldata.net/demo/LandDB/" : LandSchema
instance WaterInstance = import_csv "http://categoricaldata.net/demo/WaterDB/" : WaterSchema
#command clear = exec_cmdline { "rm -rf exportedLand" }
command exportLand = export_csv_instance LandInstance "exportedLand/"
# It's recommended to use a trailing slashes to indicate a directory,
# but the string is actually used as a prefix in a URL.
instance backAgain = import_csv "exportedLand/" : LandSchema
Keywords:
export_csv_instance
import_csv
schema_literal
Options:
instance WaterInstance
AmphibianID | isA | toAnimal |
---|
0 | 4 | 2 |
AnimalID | species |
---|
1 | FISH |
2 | frog |
instance LandInstance
AmphibianID | isA | toAnimal |
---|
0 | 6 | 3 |
1 | 8 | 5 |
AnimalID | species |
---|
2 | |
3 | Gecko |
4 | equine |
5 | FROG |
instance backAgain
AmphibianID | isA | toAnimal |
---|
0 | 6 | 4 |
1 | 8 | 2 |
AnimalID | species |
---|
2 | Gecko |
3 | |
4 | FROG |
5 | equine |
command exportLand
Export to exportedLand/.