Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: s3 sql parse error for colums as with quotes #18765

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

jiuker
Copy link
Contributor

@jiuker jiuker commented Jan 9, 2024

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers
under the terms of the Apache 2 license.
By creating this pull request I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 license.

Description

fix: s3 sql parse error
before this pr, will return error:

2024/01/09 16:42:53 1:17: unexpected token "as" (expected "FROM")

Motivation and Context

How to test this PR?

a.csv

c1|c2|c3
4|5|6
4||6
package main

import (
	"context"
	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
	"io"
	"log"
	"os"
)

func main() {
	endpoint := "127.0.0.1:9000"
	accessKeyID := "minioadmin"
	secretAccessKey := "minioadmin"
	useSSL := false
	// Initialize minio client object.
	minioClient, err := minio.New(endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
		Secure: useSSL,
	})

	opts := minio.SelectObjectOptions{
		Expression:     "select _3,_1,_2 as 'mytest'  from S3object",  // before this pr. Will return parse error.
		ExpressionType: minio.QueryExpressionTypeSQL,
		InputSerialization: minio.SelectObjectInputSerialization{
			CompressionType: minio.SelectCompressionNONE,
			CSV: &minio.CSVInputOptions{
				FileHeaderInfo:  minio.CSVFileHeaderInfoNone,
				RecordDelimiter: "\n",
				FieldDelimiter:  "|",
			},
		},
		OutputSerialization: minio.SelectObjectOutputSerialization{
			JSON: &minio.JSONOutputOptions{
				RecordDelimiter: "\n",
			},
			//CSV: &minio.CSVOutputOptions{
			//	RecordDelimiter: "\n",
			//	FieldDelimiter:  "|",
			//},
		},
	}
	opts.RequestProgress.Enabled = true

	reader, err := minioClient.SelectObjectContent(context.Background(), "mytest", "a.csv", opts)
	if err != nil {
		log.Fatalln(err)
	}
	defer reader.Close()

	if _, err := io.Copy(os.Stdout, reader); err != nil {
		log.Fatalln(err)
	}
}

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Optimization (provides speedup with no functional changes)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Fixes a regression (If yes, please add commit-id or PR # here)
  • Unit tests added/updated
  • Internal documentation updated
  • Create a documentation update request here

@jiuker jiuker changed the title fix: s3 sql parse error fix: s3 sql parse error for colums as with ' Jan 9, 2024
@jiuker jiuker changed the title fix: s3 sql parse error for colums as with ' fix: s3 sql parse error for colums as with quotes Jan 9, 2024
Copy link
Contributor

@klauspost klauspost left a comment

Choose a reason for hiding this comment

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

Please add it to the test set.

fix s3 sql parse error

ut
@donatello donatello merged commit a89e0ba into minio:master Jan 9, 2024
19 checks passed
@jiuker jiuker deleted the fix_s3_parser_error branch February 26, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants