Skip to content

Commit

Permalink
Add Test generation and goose init.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJoiner committed Mar 4, 2024
1 parent 24cab47 commit 1c4604c
Show file tree
Hide file tree
Showing 14 changed files with 1,845 additions and 38 deletions.
51 changes: 51 additions & 0 deletions clickhouse-migrations/20240304143248_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query';
CREATE TABLE IF NOT EXISTS vss (
Vehicle_Chassis_Axle_Row1_Wheel_Left_Tire_Pressure UInt16 COMMENT 'Tire pressure in kilo-Pascal.',
Vehicle_Chassis_Axle_Row1_Wheel_Right_Tire_Pressure UInt16 COMMENT 'Tire pressure in kilo-Pascal.',
Vehicle_Chassis_Axle_Row2_Wheel_Left_Tire_Pressure UInt16 COMMENT 'Tire pressure in kilo-Pascal.',
Vehicle_Chassis_Axle_Row2_Wheel_Right_Tire_Pressure UInt16 COMMENT 'Tire pressure in kilo-Pascal.',
Vehicle_CurrentLocation_Altitude Float64 COMMENT 'Current altitude relative to WGS 84 reference ellipsoid, as measured at the position of GNSS receiver antenna.',
Vehicle_CurrentLocation_Latitude Float64 COMMENT 'Current latitude of vehicle in WGS 84 geodetic coordinates, as measured at the position of GNSS receiver antenna.',
Vehicle_CurrentLocation_Longitude Float64 COMMENT 'Current longitude of vehicle in WGS 84 geodetic coordinates, as measured at the position of GNSS receiver antenna.',
Vehicle_CurrentLocation_Timestamp DateTime COMMENT 'Timestamp from GNSS system for current location, formatted according to ISO 8601 with UTC time zone.',
Vehicle_DIMO_DefinitionID String COMMENT 'ID for the vehicles definition',
Vehicle_DIMO_Source String COMMENT 'where the data was sourced from',
Vehicle_DIMO_Subject String COMMENT 'subjet of this vehicle data',
Vehicle_DIMO_Timestamp DateTime COMMENT 'timestamp of when this data was colllected',
Vehicle_DIMO_Type String COMMENT 'type of data collected',
Vehicle_DIMO_VehicleID String COMMENT 'unque DIMO ID for the vehicle',
Vehicle_Exterior_AirTemperature Float32 COMMENT 'Air temperature outside the vehicle.',
Vehicle_LowVoltageBattery_CurrentVoltage Float32 COMMENT 'Current Voltage of the low voltage battery.',
Vehicle_OBD_BarometricPressure Float32 COMMENT 'PID 33 - Barometric pressure',
Vehicle_OBD_EngineLoad Float32 COMMENT 'PID 04 - Engine load in percent - 0 = no load, 100 = full load',
Vehicle_OBD_IntakeTemp Float32 COMMENT 'PID 0F - Intake temperature',
Vehicle_OBD_RunTime Float32 COMMENT 'PID 1F - Engine run time',
Vehicle_Powertrain_CombustionEngine_ECT Int16 COMMENT 'Engine coolant temperature.',
Vehicle_Powertrain_CombustionEngine_EngineOilLevel String COMMENT 'Engine oil level.',
Vehicle_Powertrain_CombustionEngine_Speed UInt16 COMMENT 'Engine speed measured as rotations per minute.',
Vehicle_Powertrain_CombustionEngine_TPS UInt8 COMMENT 'Current throttle position.',
Vehicle_Powertrain_FuelSystem_AbsoluteLevel Float32 COMMENT 'Current available fuel in the fuel tank expressed in liters.',
Vehicle_Powertrain_FuelSystem_SupportedFuelTypes Array(String) COMMENT 'High level information of fuel types supported',
Vehicle_Powertrain_Range UInt32 COMMENT 'Remaining range in meters using all energy sources available in the vehicle.',
Vehicle_Powertrain_TractionBattery_Charging_ChargeLimit UInt8 COMMENT 'Target charge limit (state of charge) for battery.',
Vehicle_Powertrain_TractionBattery_Charging_IsCharging Bool COMMENT 'True if charging is ongoing. Charging is considered to be ongoing if energy is flowing from charger to vehicle.',
Vehicle_Powertrain_TractionBattery_GrossCapacity UInt16 COMMENT 'Gross capacity of the battery.',
Vehicle_Powertrain_TractionBattery_StateOfCharge_Current Float32 COMMENT 'Physical state of charge of the high voltage battery, relative to net capacity. This is not necessarily the state of charge being displayed to the customer.',
Vehicle_Powertrain_Transmission_TravelledDistance Float32 COMMENT 'Odometer reading, total distance travelled during the lifetime of the transmission.',
Vehicle_Speed Float32 COMMENT 'Vehicle speed.',
Vehicle_VehicleIdentification_Brand String COMMENT 'Vehicle brand or manufacturer.',
Vehicle_VehicleIdentification_Model String COMMENT 'Vehicle model.',
Vehicle_VehicleIdentification_VIN String COMMENT '17-character Vehicle Identification Number (VIN) as defined by ISO 3779.',
Vehicle_VehicleIdentification_Year UInt16 COMMENT 'Model year of the vehicle.',
)
ENGINE = MergeTree()
ORDER BY (Vehicle_DIMO_Subject, Vehicle_DIMO_Timestamp);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query';
Drop TABLE IF EXISTS vss;
-- +goose StatementEnd
3 changes: 2 additions & 1 deletion cmd/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
vspecPath := flag.String("spec", "./vspec.csv", "Path to the vspec CSV file")
migrationPath := flag.String("migrations", "./migrations.json", "Path to the migrations JSON file")
packageName := flag.String("package", "vspec", "Name of the package to generate")
withTest := flag.Bool("convert.with-test", true, "Generate test functions for conversion functions. Default is true.")
flag.Parse()

err := codegen.EnsureDir(*outputDir)
Expand All @@ -40,7 +41,7 @@ func main() {
log.Fatalf("failed to generate ClickHouse file: %v", err)
}

err = convert.Generate(&tmplData, *outputDir)
err = convert.Generate(&tmplData, *outputDir, *withTest)
if err != nil {
log.Fatalf("failed to generate convert file: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/mod v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand All @@ -8,3 +14,6 @@ golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
116 changes: 84 additions & 32 deletions internal/codegen/convert/convert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/codegen/convert/convertFunc.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// {{ convertName . }} converts data as {{ .Conversion.OriginalType }} to {{ .GOType }}
func {{ convertName . }}(val {{ .Conversion.OriginalType }}) ({{ .GOType }}, error) {
{{ if eq .Conversion.OriginalType .GOType -}}
// {{ convertName .Signal }} converts data as {{ .Signal.Conversion.OriginalType }} to {{ .Signal.GOType }}
func {{ convertName .Signal }}(val {{ .Signal.Conversion.OriginalType }}) ({{ .Signal.GOType }}, error) {
{{ if eq .Signal.Conversion.OriginalType .Signal.GOType -}}
return val, nil
{{- else -}}
panic("not implemented")
Expand Down
3 changes: 3 additions & 0 deletions internal/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func Float64Tofloat32(val float64) float32 {
if val > math.MaxFloat32 {
return math.MaxFloat32
}
if val < math.SmallestNonzeroFloat32 {
return math.SmallestNonzeroFloat32
}
return float32(val)
}

Expand Down
Loading

0 comments on commit 1c4604c

Please sign in to comment.