Summary

The updateFile() mutation replaces rows and modifies column structure in an existing lookup file within a LogScale repository. Apply incremental row updates within a defined offset and limit range, or rename, add, or remove columns across all rows. To create a new file instead, use newFile().

Syntax

graphql
updateFile(
      fileName: String!,
      name: String!,
      changedRows: [[String!]!]!,
      headers: [String!]!,
      columnChanges: [ColumnChange!]!,
      limit: Int,
      offset: Int,
      labels: [String!]
   ): UploadedFileSnapshot!

The required arguments are name, fileName, changedRows, headers, and columnChanges. The optional offset and limit arguments target a specific row range. Omitting offset truncates the file to match the provided rows.

The mutation returns a non-null UploadedFileSnapshot! object containing the file path, total row count, column headers, and other metadata about the updated file.

Input parameters

Provide the repository name, the file name, updated row data, column headers, and column changes. The optional offset and limit arguments control which rows the update targets. The following table describes each parameter.

Table: Input parameters and datatypes

Parameter Type Required Default Description
This table contains all input parameters for this mutation.
changedRows [[String!]!]! yes   The rows to write within the range defined by offset and limit. These rows overwrite all existing rows in that range.
columnChanges [ColumnChange!]! yes   Column structure changes to apply to all rows in the file. LogScale executes changes in list order: the first entry runs first, and each subsequent change operates on the result of the preceding change.
fileName String! yes   The name of the file to update within the repository.
headers [String!]! yes   The column headers for the file. Each entry corresponds to a column name in the CSV structure.
labels [String!]     Optional labels to associate with the file. Omitting this argument leaves existing labels unchanged.
limit Int     The maximum number of rows to replace, starting from offset. When provided, only the rows in that range are overwritten.
name String! yes   The name of the repository that contains the file.
offset Int     The zero-based starting row index at which to begin replacing rows. This index does not include the header row. If you omit this argument, LogScale truncates the file to match the updated rows.

The columnChanges argument accepts the ColumnChange input datatype. Specify whether a column has been added or removed at a given index. The following table provides details.

Table: ColumnChange Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
changeKindColumnChangeKindyes Long-Term The kind of column change. See ColumnChangeKind .
indexIntyes Long-Term The index of the column to change.

Example

Raw
graphql
mutation {
  updateFile( 
       fileName: "somefile.csv",
       name: "humio",
       changedRows: [ "some", "thing"],
       headers: [ "my-header" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "mutation { ^
  updateFile(  ^
       fileName: \"somefile.csv\", ^
       name: \"humio\", ^
       changedRows: [ \"some\", \"thing\"], ^
       headers: [ \"my-header\" ], ^
       columnChanges: [ { changeKind: Remove, index: 1 } ] ^
  ) ^
  { lines } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "mutation {
  updateFile( 
       fileName: \"somefile.csv\",
       name: \"humio\",
       changedRows: [ \"some\", \"thing\"],
       headers: [ \"my-header\" ],
       columnChanges: [ { changeKind: Remove, index: 1 } ]
  )
  { lines }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "updateFile": {
      "lines": "4"
    }
  }
}

Returned values

The mutation returns a non-null UploadedFileSnapshot! object providing the file path, total row count, column headers, and other metadata about the updated file. The following table describes the available fields.

Table: UploadedFileSnapshot Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
filterStringString  Long-Term Any string on which to filter the data.
headersStringyes Long-Term The headers for the uploaded snapshot file.
limitIntyes Long-Term The file upload limit.
lines[String]yes Long-Term The contents of the file in the form of a list of lines, with each line being itself a list of column values. When the file is empty or nothing matches filterString, then [] is returned.
nameAndPathFileNameAndPathyes Long-Term The name and path of the uploaded snapshot file. See FileNameAndPath.
offsetIntyes Long-Term This is the offset supplied to a file query. For a new or updated file, this is always 0.
resourceStringyes Short-Term The resource identifier for the file.
totalLinesCountLongyes Long-Term The total number of lines in the uploaded snapshot file.