googleapis/google-cloud-php

Problem with createDataset

cluttgue opened this issue · 0 comments

Environment details

  • OS: Windows 10
  • PHP version: 8.2.12
  • Package name and version: cloud-ai-platform v.1.3

Steps to reproduce

  1. I'm use the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php for create a Dataset for Tabular data, when I called the example I have the next error:
foreach() argument must be of type array|object, null given

  at vendor\google\gax\src\RequestBuilder.php:174
    170▕
    171▕         $body = null;
    172▕         $queryParams = [];
    173▕         $messageData = json_decode($messageDataJson, true);
  ➜ 174▕         foreach ($messageData as $name => $value) {
    175▕             if (array_key_exists($name, $config['placeholders'])) {
    176▕                 continue;
    177▕             }
    178▕

  1   vendor\google\gax\src\RequestBuilder.php:174
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("foreach() argument must be of type array|object, null given", "C:\...\vendor\google\gax\src\RequestBuilder.php")

  2   vendor\google\gax\src\RequestBuilder.php:110
      Google\ApiCore\RequestBuilder::constructBodyAndQueryParameters(Object(Google\Cloud\AIPlatform\V1\CreateDatasetRequest), ["post", "/v1/{parent=projects/*/locations/*}/datasets", "dataset"])

The code it's the same of the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php.

Code example

// The called to function are:

 $formattedParent = DatasetServiceClient::locationName('lab-ia-430919', 'us-central1');
        $this->create_dataset(
            $formattedParent,
            'example-ventas',
            'gs://bucket-ia-example/schemaDatasetVertexAI.yaml'
        );


    function create_dataset(
        string $formattedParent,
        string $datasetDisplayName,
        string $datasetMetadataSchemaUri
    ): void {
        // Create a client.
        $datasetServiceClient = new DatasetServiceClient();

        // Prepare the request message.
        $datasetMetadata = new Value();
        $dataset = (new Dataset())
            ->setName($datasetDisplayName)
            ->setDisplayName($datasetDisplayName)
            ->setMetadataSchemaUri($datasetMetadataSchemaUri)
            ->setMetadata($datasetMetadata);
        $request = (new CreateDatasetRequest())
            ->setParent($formattedParent)
            ->setDataset($dataset);


        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $datasetServiceClient->createDataset($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var Dataset $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }