-
Notifications
You must be signed in to change notification settings - Fork 353
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
INVALID_ARGUMENT error when creating non-incremental materialized view using MaterializedViewDefinition.setMaxStaleness #20328
Comments
Hi @jingc-ac, thanks for sharing your concern. At a glance, it seems like the Also, there is a more up-to-date bigquery library in case you were not aware of it. It includes a sample on materialized views |
Hi @diegomarquezp I'm not using google-cloud-bigquery lib, i'm using "com.google.apis" % "google-api-services-bigquery" % "v2-rev20240229-2.0.0" import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.services.bigquery.Bigquery
import com.google.api.client.json.gson.GsonFactory
import com.google.auth.http.HttpCredentialsAdapter
import com.google.auth.oauth2.GoogleCredentials
import com.google.api.services.bigquery.model.{MaterializedViewDefinition, Table, TableReference}
def main(args: Array[String]): Unit = {
val projectId = "..."
val datasetName = "..."
val materializedViewName = "..."
val query = "SELECT..."
val bigquery = createAuthorizedClient
createNonIncrementalMaterializedView(bigquery, projectId, datasetName, materializedViewName, query)
}
def createAuthorizedClient: Bigquery = {
val credentials = GoogleCredentials.getApplicationDefault
val requestInitializer = new HttpCredentialsAdapter(credentials)
val HTTP_TRANSPORT = new NetHttpTransport
val JSON_FACTORY = new GsonFactory
new Bigquery.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
.setApplicationName("test/1.0")
.build()
}
def createNonIncrementalMaterializedView(bigquery: Bigquery, projectId: String, datasetName: String, materializedViewName: String, query: String): Unit = {
try {
val tView = new Table
val tableRef = new TableReference
tableRef.setTableId(materializedViewName)
tableRef.setDatasetId(datasetName)
tableRef.setProjectId(projectId)
tView.setTableReference(tableRef)
val viewDef = (new MaterializedViewDefinition).setQuery(query)
.setAllowNonIncrementalDefinition(true)
.setMaxStaleness("INTERVAL \"4\" HOUR")
tView.setMaterializedView(viewDef)
bigquery.tables.insert(projectId, datasetName, tView).execute
System.out.println(s"Materialized view ${projectId}.${datasetName}.${materializedViewName} created successfully")
} catch {
case e: Throwable =>
System.out.println(s"Materialized view ${projectId}.${datasetName}.${materializedViewName} was not created. \n" + e.toString)
}
} |
Thank you for sharing the reproducer. I did create a java version of it to ease the troubleshooting on our side. You were right about I'll get back to you after inspecting the requests being created |
@diegomarquezp it turns out both tView.setMaterializedView(viewDef).setMaxStaleness("0-0 0 4:0:0") This is confusing |
Glad you found out the solution. This is indeed something not obvious judging from the documentation and should be addressed. @suztomo apparently the only source of usage information is the javadoc plus some generic documentation in the official docs |
@jingc-ac Which document did you reference when you created this issue? |
Thank you.
You read some document when you wanted to create a non-incremental materialized view. What was that document? |
Hi @jingc-ac. Was this the only source of information to produce the code that worked? |
I'm using v2-rev20240229-2.0.0 and want to create a non-incremental materialized view, so i created MaterializedViewDefinition like:
got error:
I tried many formats of maxStaleness as follow, always same error.
"INTERVAL "4" HOUR"
"INTERVAL 4 HOUR"
"4 hours"
"INTERVAL "4:0:0" HOUR TO SECOND"
"4:0:0"
"INTERVAL '4:0:0' HOUR TO SECOND"
"0-0 103 16:10:25"
"'4:0:0' HOUR TO SECOND"
"4 HOUR"
which format should I use?
The text was updated successfully, but these errors were encountered: