Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ src/Backend/test_data/json

# Allow s3_source directory
!src/Backend/test_data/s3_source/
!src/Backend/test_data/s3_source/**
!src/Backend/test_data/s3_source/**

# Allow a specific CSV dataset that we want tracked despite the general csv ignores
!src/Backend/test_data/csv/
!src/Backend/test_data/csv/Mental_Health_and_Social_Media_Balance_Dataset.csv
# allow parquet file
!src/Backend/test_data/parquet/
!src/Backend/test_data/parquet/capitals_clean.parquet
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ We use a Makefile to simplify common development tasks. All commands should be r
```bash
make go-test-coverage
```
- Run test with html coverage
```bash
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
```


### Rust Tests
- Run all tests
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ go-test-coverage:
@echo "Running Go tests with coverage..."
cd src/Backend/opti-sql-go && go test -v -coverprofile=coverage.out ./...
cd src/Backend/opti-sql-go && go tool cover -func=coverage.out

go-run:
@echo "Running Go application..."
cd src/Backend/opti-sql-go && go run main.go
Expand Down
34 changes: 30 additions & 4 deletions src/Backend/opti-sql-go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ var (
)

type Config struct {
Server serverConfig `yaml:"server"`
Batch batchConfig `yaml:"batch"`
Query queryConfig `yaml:"query"`
Metrics metricsConfig `yaml:"metrics"`
Server serverConfig `yaml:"server"`
Batch batchConfig `yaml:"batch"`
Query queryConfig `yaml:"query"`
Metrics metricsConfig `yaml:"metrics"`
Secretes secretesConfig // do not read these from yaml
}
type serverConfig struct {
Port int `yaml:"port"`
Expand All @@ -32,6 +33,8 @@ type batchConfig struct {
EnableParallelRead bool `yaml:"enable_parallel_read"`
MaxMemoryBeforeSpill uint64 `yaml:"max_memory_before_spill"`
MaxFileSizeMB int `yaml:"max_file_size_mb"` // max size of a single file
ShouldDownload bool `yaml:"should_download"`
MaxDownloadSizeMB int `yaml:"max_download_size_mb"` // max size to download from external sources like S3
}
type queryConfig struct {
// should results be cached, server side? if so how long
Expand All @@ -51,6 +54,12 @@ type metricsConfig struct {
// memory usage over time
EnableMemoryStats bool `yaml:"enable_memory_stats"`
}
type secretesConfig struct {
AccessKey string `yaml:"access_key"`
SecretKey string `yaml:"secret_key"`
EndpointURL string `yaml:"endpoint_url"`
BucketName string `yaml:"bucket_name"`
}

var configInstance *Config = &Config{
Server: serverConfig{
Expand All @@ -64,6 +73,10 @@ var configInstance *Config = &Config{
EnableParallelRead: true,
MaxMemoryBeforeSpill: uint64(gigaByte) * 2, // 2GB
MaxFileSizeMB: 500, // 500MB
// should we download files from external sources like S3
// if so whats the max size to download, if its greater than dont download the file locally
ShouldDownload: true,
MaxDownloadSizeMB: 10, // 10MB
},
Query: queryConfig{
EnableCache: true,
Expand All @@ -79,6 +92,13 @@ var configInstance *Config = &Config{
EnableQueryStats: true,
EnableMemoryStats: true,
},
// TODO: remove hardcoded secretes before production. we are just testing for now
Secretes: secretesConfig{
AccessKey: "DO8013ZT6VDHJ2EM94RN",
SecretKey: "kPvQSMt6naiwe/FhDnzXpYmVE5yzJUsIR0/OJpsUNzo",
EndpointURL: "atl1.digitaloceanspaces.com",
BucketName: "test-bucket-pull-down",
Comment on lines +95 to +100
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded AWS/S3 credentials (Access Key and Secret Key) are exposed in the codebase. These sensitive credentials should never be committed to version control. Use environment variables or a secure secrets management system instead.

Suggested change
// TODO: remove hardcoded secretes before production. we are just testing for now
Secretes: secretesConfig{
AccessKey: "DO8013ZT6VDHJ2EM94RN",
SecretKey: "kPvQSMt6naiwe/FhDnzXpYmVE5yzJUsIR0/OJpsUNzo",
EndpointURL: "atl1.digitaloceanspaces.com",
BucketName: "test-bucket-pull-down",
// Load secrets from environment variables for security
Secretes: secretesConfig{
AccessKey: os.Getenv("AWS_ACCESS_KEY"),
SecretKey: os.Getenv("AWS_SECRET_KEY"),
EndpointURL: os.Getenv("AWS_ENDPOINT_URL"),
BucketName: os.Getenv("AWS_BUCKET_NAME"),

Copilot uses AI. Check for mistakes.
},
}

func GetConfig() *Config {
Expand Down Expand Up @@ -138,6 +158,12 @@ func mergeConfig(dst *Config, src map[string]interface{}) {
if v, ok := batch["max_file_size_mb"].(int); ok {
dst.Batch.MaxFileSizeMB = v
}
if v, ok := batch["should_download"].(bool); ok {
dst.Batch.ShouldDownload = v
}
if v, ok := batch["max_download_size_mb"].(int); ok {
dst.Batch.MaxDownloadSizeMB = v
}
}

// =============================
Expand Down
28 changes: 28 additions & 0 deletions src/Backend/opti-sql-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,45 @@ module opti-sql-go
go 1.24.0

require (
github.com/apache/arrow/go/v15 v15.0.2
github.com/apache/arrow/go/v17 v17.0.0
github.com/aws/aws-sdk-go v1.55.8
github.com/aws/aws-sdk-go-v2 v1.39.6
github.com/aws/aws-sdk-go-v2/service/s3 v1.90.2
github.com/joho/godotenv v1.5.1
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/apache/thrift v0.20.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.13 // indirect
github.com/aws/smithy-go v1.23.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/asmfmt v1.3.2 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/minio/minio-go v6.0.14+incompatible // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
Expand Down
56 changes: 56 additions & 0 deletions src/Backend/opti-sql-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,27 +1,82 @@
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c h1:RGWPOewvKIROun94nF7v2cua9qP+thov/7M50KEoeSU=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/apache/arrow/go/v15 v15.0.2 h1:60IliRbiyTWCWjERBCkO1W4Qun9svcYoZrSLcyOsMLE=
github.com/apache/arrow/go/v15 v15.0.2/go.mod h1:DGXsR3ajT524njufqf95822i+KTh+yea1jass9YXgjA=
github.com/apache/arrow/go/v17 v17.0.0 h1:RRR2bdqKcdbss9Gxy2NS/hK8i4LDMh23L6BbkN5+F54=
github.com/apache/arrow/go/v17 v17.0.0/go.mod h1:jR7QHkODl15PfYyjM2nU+yTLScZ/qfj7OSUZmJ8putc=
github.com/apache/thrift v0.20.0 h1:631+KvYbsBZxmuJjYwhezVsrfc/TbqtZV4QcxOX1fOI=
github.com/apache/thrift v0.20.0/go.mod h1:hOk1BQqcp2OLzGsyVXdfMk7YFlMxK3aoEVhjD06QhB8=
github.com/aws/aws-sdk-go v1.55.8 h1:JRmEUbU52aJQZ2AjX4q4Wu7t4uZjOu71uyNmaWlUkJQ=
github.com/aws/aws-sdk-go v1.55.8/go.mod h1:ZkViS9AqA6otK+JBBNH2++sx1sgxrPKcSzPPvQkUtXk=
github.com/aws/aws-sdk-go-v2 v1.39.6 h1:2JrPCVgWJm7bm83BDwY5z8ietmeJUbh3O2ACnn+Xsqk=
github.com/aws/aws-sdk-go-v2 v1.39.6/go.mod h1:c9pm7VwuW0UPxAEYGyTmyurVcNrbF6Rt/wixFqDhcjE=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3 h1:DHctwEM8P8iTXFxC/QK0MRjwEpWQeM9yzidCRjldUz0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.3/go.mod h1:xdCzcZEtnSTKVDOmUZs4l/j3pSV6rpo1WXl5ugNsL8Y=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.13 h1:a+8/MLcWlIxo1lF9xaGt3J/u3yOZx+CdSveSNwjhD40=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.13/go.mod h1:oGnKwIYZ4XttyU2JWxFrwvhF6YKiK/9/wmE3v3Iu9K8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.13 h1:HBSI2kDkMdWz4ZM7FjwE7e/pWDEZ+nR95x8Ztet1ooY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.13/go.mod h1:YE94ZoDArI7awZqJzBAZ3PDD2zSfuP7w6P2knOzIn8M=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.13 h1:eg/WYAa12vqTphzIdWMzqYRVKKnCboVPRlvaybNCqPA=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.13/go.mod h1:/FDdxWhz1486obGrKKC1HONd7krpk38LBt+dutLcN9k=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 h1:x2Ibm/Af8Fi+BH+Hsn9TXGdT+hKbDd5XOTZxTMxDk7o=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3/go.mod h1:IW1jwyrQgMdhisceG8fQLmQIydcT/jWY21rFhzgaKwo=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.4 h1:NvMjwvv8hpGUILarKw7Z4Q0w1H9anXKsesMxtw++MA4=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.4/go.mod h1:455WPHSwaGj2waRSpQp7TsnpOnBfw8iDfPfbwl7KPJE=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13 h1:kDqdFvMY4AtKoACfzIGD8A0+hbT41KTKF//gq7jITfM=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13/go.mod h1:lmKuogqSU3HzQCwZ9ZtcqOc5XGMqtDK7OIc2+DxiUEg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.13 h1:zhBJXdhWIFZ1acfDYIhu4+LCzdUS2Vbcum7D01dXlHQ=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.13/go.mod h1:JaaOeCE368qn2Hzi3sEzY6FgAZVCIYcC2nwbro2QCh8=
github.com/aws/aws-sdk-go-v2/service/s3 v1.90.2 h1:DhdbtDl4FdNlj31+xiRXANxEE+eC7n8JQz+/ilwQ8Uc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.90.2/go.mod h1:+wArOOrcHUevqdto9k1tKOF5++YTe9JEcPSc9Tx2ZSw=
github.com/aws/smithy-go v1.23.2 h1:Crv0eatJUQhaManss33hS5r40CG3ZFH+21XSkqMrIUM=
github.com/aws/smithy-go v1.23.2/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/asmfmt v1.3.2 h1:4Ri7ox3EwapiOjCki+hw14RyKk201CN4rzyCJRFLpK4=
github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 h1:AMFGa4R4MiIpspGNG7Z948v4n35fFGB3RR3G/ry4FWs=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 h1:+n/aFZefKZp7spd8DFdX7uMikMLXX4oubIzJF4kv/wI=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/minio/minio-go v6.0.14+incompatible h1:fnV+GD28LeqdN6vT2XdGKW8Qe/IfjJDswNVuni6km9o=
github.com/minio/minio-go v6.0.14+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
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/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
Expand All @@ -48,5 +103,6 @@ google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDom
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions src/Backend/opti-sql-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
)

// TODO: in the project operators make sure the record batches account for the RowCount field properly.

func main() {
if len(os.Args) > 1 {
if err := config.Decode(os.Args[1]); err != nil {
Expand Down
107 changes: 103 additions & 4 deletions src/Backend/opti-sql-go/operators/Expr/expr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,105 @@
package Expr

// evaluate expressions
// for example Column + Literal
// Column - Column
// Literal / Literal
import "github.com/apache/arrow/go/v17/arrow"

type binaryOperator int

const (
// arithmetic
addition binaryOperator = 1
subtraction binaryOperator = 2
multiplication binaryOperator = 3
division binaryOperator = 4
modulous binaryOperator = 5
// comparison
equal binaryOperator = 6
notEqual binaryOperator = 7
lessThan binaryOperator = 8
lessThanOrEqual binaryOperator = 9
greaterThan binaryOperator = 10
greaterThanOrEqual binaryOperator = 11
// logical
and binaryOperator = 12
or binaryOperator = 13
not binaryOperator = 14
)

type supportedFunctions int

const (
upper supportedFunctions = 1
lower supportedFunctions = 2
abs supportedFunctions = 3
round supportedFunctions = 4
)

type aggFunctions = int

const (
Sum aggFunctions = 1
Count aggFunctions = 2
Avg aggFunctions = 3
Min aggFunctions = 4
Max aggFunctions = 5
)

/*
Eval(expr):

match expr:
Literal(x) -> return x
Column(name) -> return array of that column
BinaryExpr(left > right) -> eval left, eval right, apply operator
ScalarFunction(upper(name)) -> evaluate function
Alias(expr, name) -> just a name wrapper
*/
type Expr interface {
ExprNode() // empty method, only for the sake of polymophism
}

/*
Alias | sql: select col1 as new_name from table_source
updates the column name in the output schema.
*/
type Alias struct {
expr []Expr
columnName string
name string
}

// return batch.Columns[fieldIndex["age"]]
// resolves the arrow array corresponding to name passed in
// sql: select age
type ColumnResolve struct {
name string
}

// Evaluates to a column of length = batch-size, filled with this literal.
// sql: select 1
type LiteralResolve struct {
Type arrow.DataType
value any
}

type Operator struct {
o binaryOperator
}
type BinaryExpr struct {
left []Expr
op Operator
right []Expr
}

type ScalarFunction struct {
function supportedFunctions
input []Expr // resolve to something you can procees IE, literal/coloumn Resolve
}
type AggregateFunction struct {
function aggFunctions
args []Expr
}

type CastExpr struct {
expr []Expr // can be a Literal or Column (check for datatype then)
targetType arrow.DataType
}
Empty file.
25 changes: 21 additions & 4 deletions src/Backend/opti-sql-go/operators/filter/filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package filter

// handle Bitwise operations here as well
import (
"github.com/apache/arrow/go/v17/arrow"
"github.com/apache/arrow/go/v17/arrow/array"
)

// OR
// AND
// NOT
// FilterExpr takes in a field and column and yeilds a function that takes in an index and returns a bool indicating whether the row at that index satisfies the filter condition.
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in documentation comment: 'yeilds' should be 'yields'.

Suggested change
// FilterExpr takes in a field and column and yeilds a function that takes in an index and returns a bool indicating whether the row at that index satisfies the filter condition.
// FilterExpr takes in a field and column and yields a function that takes in an index and returns a bool indicating whether the row at that index satisfies the filter condition.

Copilot uses AI. Check for mistakes.
type FilterExpr func(filed arrow.Field, col arrow.Array) func(i int) bool
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in parameter name: 'filed' should be 'field'.

Suggested change
type FilterExpr func(filed arrow.Field, col arrow.Array) func(i int) bool
type FilterExpr func(field arrow.Field, col arrow.Array) func(i int) bool

Copilot uses AI. Check for mistakes.

// example
func ExampleFilterExpr(field arrow.Field, col arrow.Array) func(i int) bool {
{
if field.Name == "age" && col.DataType().ID() == arrow.INT32 {
return func(i int) bool {
val := col.(*array.Int32).Value(i)
return val > 30
}
}
return func(i int) bool {
return true
}
}
}
Loading
Loading