Repeated option in protocol Buffer

183 views
Skip to first unread message

SUDHAVANI SUNKARA

unread,
Nov 29, 2022, 10:30:00 PM11/29/22
to Protocol Buffers
Hi 

I am trying to use BQ subscription to write into BQ table. I am using pubsub schema and trying to use protocol buffer option.
Here is my schema

syntax = "proto2";

message SkuCostAudit {
    message costs{
        required string calculatedDateTime = 1;
        required int64 sku = 2;
    required int64 vendor = 3;
    required int64 location = 4;
    required string locationType = 5;
    required float cost = 6;
    required string effectiveBeginDateTime = 7;
    required string effectiveEndDateTime = 8;
    required string transactionType = 9;
    required string details = 10;
    }
   
    repeated costs xyz = 11;
}

I am trying to test my schema with this pubsub message..

{
   "costs":[
      {
         "calculatedDateTime":"2022-11-29T15:38:47Z",
         "sku":122222222,
         "vendor":111111,
         "location":1234,
         "locationType":"",
         "cost":200.1200,
         "effectiveBeginDateTime":"2019-12-25T07:00:00Z",
         "effectiveEndDateTime":"2022-11-17T06:59:59Z",
         "transactionType":"INSERT",
         "details":[
            {
               "type":"PERMANENT",
               "cost":200.1200,
               "effective":true
            }
         ]
      },
      {
         "calculatedDateTime":"2022-11-29T15:38:47Z",
         "sku":222222222,
         "vendor":222222,
         "location":2222,
         "locationType":"",
         "cost":45,
         "effectiveBeginDateTime":"2022-11-17T07:00:00Z",
         "effectiveEndDateTime":"2023-11-24T06:59:59Z",
         "transactionType":"INSERT",
         "details":[
            {
               "type":"PERMANENT",
               "cost":45,
               "effective":true
            }
         ]
      },
      {
         "calculatedDateTime":"2022-11-29T15:38:47Z",
         "sku":3333333333,
         "vendor":44444444,
         "location":2222,
         "locationType":"",
         "cost":200.1200,
         "effectiveBeginDateTime":"2019-12-25T07:00:00Z",
         "effectiveEndDateTime":"9999-12-30T23:59:59Z",
         "transactionType":"DELETE",
         "details":[
            {
               "type":"PERMANENT",
               "cost":200.1200,
               "effective":true
            }
         ]
      }
   ]
}

I am getting error "Message is invalid against schema" . My pubsub message is correct. Can someone guide me to fix my schema? 

Derek Perez

unread,
Nov 29, 2022, 10:33:34 PM11/29/22
to SUDHAVANI SUNKARA, Protocol Buffers
Looks like details needs to be a repeated message with its own schema and you have it set to required and string.  

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/de950a92-ffe3-4796-b1c4-ba22f290d70an%40googlegroups.com.

SUDHAVANI SUNKARA

unread,
Nov 29, 2022, 10:39:55 PM11/29/22
to Protocol Buffers
Thank you  DE.

I tried this still same isuue

syntax = "proto2";

message SkuCostAudit {
    message costs{
        required string calculatedDateTime = 1;
        required int64 sku = 2;
    required int64 vendor = 3;
    required int64 location = 4;
    required string locationType = 5;
    required float cost = 6;
    required string effectiveBeginDateTime = 7;
    required string effectiveEndDateTime = 8;
    required string transactionType = 9;
    required details details = 10;
    }
    message details{
    required string type = 13;
    required float cost = 14;
    required string effective = 15;

  }
    repeated costs xyz = 11;


Derek Perez

unread,
Nov 29, 2022, 10:51:27 PM11/29/22
to SUDHAVANI SUNKARA, Protocol Buffers
Say “repeated” instead of “required” for details/10 line. 

SUDHAVANI SUNKARA

unread,
Nov 29, 2022, 10:54:41 PM11/29/22
to Protocol Buffers
I have this

syntax = "proto2";

message SkuCostAudit {
    message costs{
        required string calculatedDateTime = 1;
        required int64 sku = 2;
    required int64 vendor = 3;
    required int64 location = 4;
    required string locationType = 5;
    required float cost = 6;
    required string effectiveBeginDateTime = 7;
    required string effectiveEndDateTime = 8;
    required string transactionType = 9;
    repeated details details = 10;
    }
    message details{
    required string type = 12;
    required float cost = 13;
    required string effective = 14;

  }
    repeated costs xyz = 11;
}



Still getting error

Invalid JSON-encoded message against Protocol Buffer schema. Syntax error: value, object or array expected.

Derek Perez

unread,
Nov 29, 2022, 10:56:09 PM11/29/22
to SUDHAVANI SUNKARA, Protocol Buffers
Hard to say without seeing more details/code. Sorry :(

SUDHAVANI SUNKARA

unread,
Nov 29, 2022, 10:59:06 PM11/29/22
to Protocol Buffers
Thank you DE. I  did not write any code DE.

I am trying to create schema. Am I missing any [ ] ?
My pubsub message is correct. I am  trying  to match my schema with pubsub message. 

Derek Perez

unread,
Nov 29, 2022, 11:02:34 PM11/29/22
to SUDHAVANI SUNKARA, Protocol Buffers
That schema looks correct to me, so I'm not really sure how to help further...could try syntax = "proto3" and drop all the required.

SUDHAVANI SUNKARA

unread,
Nov 29, 2022, 11:08:16 PM11/29/22
to Protocol Buffers
Tried this.
syntax = "proto3";

message SkuCostAudit {
    message costs{
         string calculatedDateTime = 1;
         int64 sku = 2;
     int64 vendor = 3;
     int64 location = 4;
     string locationType = 5;
     float cost = 6;
     string effectiveBeginDateTime = 7;
     string effectiveEndDateTime = 8;
     string transactionType = 9;
    repeated details detail = 10;
    }
    message details{
     string type = 11;
     float cost = 12;
     string effective = 13;
  }
    repeated costs xyz = 14;
}

But no luck. Invalid JSON-encoded message against Protocol Buffer schema. Syntax error: value, object or array expected. 
Reply all
Reply to author
Forward
0 new messages