Skip to content

Commit

Permalink
Merge 7596655 into 5de1559
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyPA authored Aug 21, 2024
2 parents 5de1559 + 7596655 commit 9b276bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ydb/library/yql/providers/s3/provider/yql_s3_datasink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@ class TS3DataSinkProvider : public TDataProviderBase {
TExprNode::TPtr RewriteIO(const TExprNode::TPtr& write, TExprContext& ctx) override {
const TS3Write w(write);
auto settings = write->Tail().ChildrenList();

TExprNode::TPtr format = ExtractFormat(settings);
if (!format) {
ctx.AddError(TIssue(ctx.GetPosition(write->Pos()), "Missing format - please use WITH FORMAT when writing into S3"));
return nullptr;
}

return Build<TS3WriteObject>(ctx, w.Pos())
.World(w.World())
.DataSink(w.DataSink())
.Target<TS3Target>()
.Path(write->Child(2U)->Head().Tail().HeadPtr())
.Format(ExtractFormat(settings))
.Format(std::move(format))
.Settings(ctx.NewList(w.Pos(), std::move(settings)))
.Build()
.Input(write->ChildPtr(3))
Expand Down
25 changes: 25 additions & 0 deletions ydb/tests/fq/s3/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,28 @@ def test_insert_empty_object(self, kikimr, s3, client, unique_prefix):
assert result_set.columns[0].type.type_id == ydb.Type.STRING
assert len(result_set.rows) == 1
assert result_set.rows[0].items[0].text_value == ""

@yq_all
@pytest.mark.parametrize("client", [{"folder_id": "my_folder"}], indirect=True)
def test_insert_without_format_error(self, kikimr, s3, client, unique_prefix):
resource = boto3.resource(
"s3", endpoint_url=s3.s3_url, aws_access_key_id="key", aws_secret_access_key="secret_key"
)

bucket = resource.Bucket("insert_bucket")
bucket.create(ACL='public-read-write')
bucket.objects.all().delete()

storage_connection_name = unique_prefix + "ibucket"
client.create_storage_connection(storage_connection_name, "insert_bucket")

sql = f'''
insert into `{storage_connection_name}`.`/test/`
select * from AS_TABLE([<|foo:123, bar:"xxx"u|>,<|foo:456, bar:"yyy"u|>]);
'''

query_id = client.create_query("simple", sql, type=fq.QueryContent.QueryType.ANALYTICS).result.query_id
client.wait_query_status(query_id, fq.QueryMeta.FAILED)
issues = str(client.describe_query(query_id).result.query.issue)

assert "Missing format - please use WITH FORMAT when writing into S3" in issues, "Incorrect Issues: " + issues

0 comments on commit 9b276bd

Please sign in to comment.