我有一个.csv文件,我想将其附加到我的BigQuery数据集/表中,其中一列的格式为dd.mm.yyyy。由于我想使用分区表,因此我需要一列的格式为DATE。
但是,我不确定如何只为一列设置架构。我尝试了以下方法:
ValueError: Error when checking input: expected dense_32_input to have 4 dimensions, but got array with shape (6, 4, 3)
但是它给出了错误:
google.api_core.exceptions.BadRequest:400读取数据时出错, 错误消息:CSV表遇到太多错误,放弃了。行数: 1;错误:1.请查看errors []集合以获取更多信息 详细信息。
当我取出from google.cloud import bigquery as bq
dataset_ref = client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
job_config = bq.LoadJobConfig()
job_config.write_disposition = bq.WriteDisposition.WRITE_APPEND
job_config.source_format = bq.SourceFormat.CSV
job_config.field_delimiter = delimiter
job_config.skip_leading_rows = 1
job_config.autodetect = True
job_config.schema_update_options = [
bq.SchemaUpdateOption.ALLOW_FIELD_ADDITION,
]
job_config.schema = [
bq.SchemaField('date_col', 'DATE')
]
job = client.load_table_from_file(
source_file,
table_ref,
location="europe-west2", # Must match the destination dataset location.
job_config=job_config) # API request
job.result() # Waits for table load to complete.
选项时,它可以正常工作,但随后将其作为STRING导入。
答案 0 :(得分:0)
自all the columns names and types are required when setting it起,您不能在架构中仅指定一列。另一方面,将格式为 <?php
/* Connection data */
$servername = "localhost";
$username = "root";
$password = "";
$databasename = "m4wb";
/* Connection attempt */
$database_connection = mysqli_connect($servername, $username, $password, $databasename);
/* Connection verification */
if ($database_connection) {
echo "Connected to database.";
} else {
echo "Not connected to database.";
}
/* Requested action */
$requested_action = $_POST["requested_action"]; // '$_POST' is an array that stores all information sent in a 'POST' request
echo $requested_action;
/* Requested action verification */
// If a request to save the answers to our questionnaire was made, (...)
if ($requested_action == "save_answers") {
// (...) we get the data that was sent along with the request, (...)
$question_1 = $_POST["question_1"];
$question_1_1 = $_POST["question_1_1"];
$question_2 = $_POST["question_2"];
$question_2_1 = $_POST["question_2_1"];
$question_3 = json_encode($_POST["question_3"]); // We can't directly store arrays in a database, so we use 'json_encode()' to turn the array into a string
$question_3_1 = $_POST["question_3_1"];
$bar_chart_colors = json_encode($_POST["bar_chart_colors"]); // We can't directly store arrays in a database, so we use 'json_encode()' to turn the array into a string
$question_4 = json_encode($_POST["question_4"]); // We can't directly store arrays in a database, so we use 'json_encode()' to turn the array into a string
$question_5 = $_POST["question_5"];
$question_6 = $_POST["question_6"];
$question_6_1 = $_POST["question_6_1"];
echo $question_1, $question_1_1, $question_2, $question_2_1, $question_3, $question_3_1, $bar_chart_colors, $question_4, $question_5, $question_6, $question_6_1;
// (...) we prepare our query, (...)
$query = "INSERT INTO answer ('ID', 'USER_ID', 'CONTENT_ID', 'Q_ONE', 'Q_ONE_ONE', 'Q_TWO', 'Q_TWO_ONE', 'Q_THREE', 'Q_THREE_ONE', 'BAR_CHART_COLORS', 'Q_FOUR', 'Q_FIVE', 'Q_SIX', 'Q_SIX_ONE') VALUES ('1', '1', '1', '$question_1', '$question_1_1', '$question_2', '$question_2_1', '$question_3', '$question_3_1', '$bar_chart_colors', '$question_4', '$question_5', '$question_6', '$question_6_1')";
// (...) we execute the query, we save its result ('TRUE' or 'FALSE'), (...)
$query_result = mysqli_query($database_connection, $query);
echo $query_result;
// (...) we commit the current transaction, (...)
mysqli_commit($database_connection);
// (...) we close our database connection, (...)
mysqli_close($database_connection);
// (...) and we exit this PHP script
exit("Exited!");
}
var_dump($_POST);
exit("Exited!");
?>
的日期加载到BigQuery中时,不能将其解析为dd.mm.yyyy
,因此您必须将其加载为DATE
,然后将其导入BigQuery后进行解析。否则,您将必须change your data format to YYYY-MM-DD
。