Skip to content
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

add HopMetadataProperty to sql file output, fixes #1935 #4856

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ public boolean processRow() throws HopException {
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
data.insertRowMeta = getInputRowMeta().clone();

if (meta.isDoNotOpenNewFileInit()) {
if (!openNewFile()) {
logError("Couldn't open file [" + buildFilename() + "]");
setErrors(1);
return false;
}
if (meta.getFile().isDoNotOpenNewFileInit() && !openNewFile()) {
logError("Couldn't open file [" + buildFilename() + "]");
setErrors(1);
return false;
}
}

Expand All @@ -80,26 +78,24 @@ public boolean processRow() throws HopException {

if (r != null
&& getLinesOutput() > 0
&& meta.getSplitEvery() > 0
&& ((getLinesOutput() + 1) % meta.getSplitEvery()) == 0) {
&& meta.getFile().getSplitEvery() > 0
&& ((getLinesOutput() + 1) % meta.getFile().getSplitEvery()) == 0) {

// Done with this part or with everything.
closeFile();

// Not finished: open another file...
if (r != null) {
if (!openNewFile()) {
logError("Unable to open new file (split #" + data.splitnr + "...");
setErrors(1);
return false;
}
if (r != null && !openNewFile()) {
logError("Unable to open new file (split #" + data.splitnr + "...");
setErrors(1);
return false;
}
}

try {
if (getLinesOutput() == 0) {
// Add creation table once to the top
if (meta.createTable()) {
if (meta.isCreateTable()) {
String crTable = data.db.getDDLCreationTable(schemaTable, data.insertRowMeta);

if (isRowLevel()) {
Expand All @@ -110,7 +106,7 @@ && getLinesOutput() > 0
}

// Truncate table
if (meta.truncateTable()) {
if (meta.isTruncateTable()) {
// Write to file
String truncatetable =
data.db.getDDLTruncateTable(schemaName, tableName + ";" + Const.CR + Const.CR);
Expand All @@ -128,7 +124,7 @@ && getLinesOutput() > 0
+ ";";

// Do we start a new line for this statement ?
if (meta.StartNewLine()) {
if (meta.isStartNewLine()) {
sql = sql + Const.CR;
}

Expand All @@ -146,10 +142,8 @@ && getLinesOutput() > 0
putRow(data.outputRowMeta, r); // in case we want it go further...
incrementLinesOutput();

if (checkFeedback(getLinesRead())) {
if (isBasic()) {
logBasic("linenr " + getLinesRead());
}
if (checkFeedback(getLinesRead()) && isBasic()) {
logBasic("linenr " + getLinesRead());
}
} catch (HopException e) {

Expand All @@ -176,7 +170,7 @@ && getLinesOutput() > 0
}

public String buildFilename() {
return meta.buildFilename(this, resolve(meta.getFileName()), getCopy(), data.splitnr);
return meta.buildFilename(this, resolve(meta.getFile().getFileName()), getCopy(), data.splitnr);
}

public boolean openNewFile() {
Expand All @@ -186,7 +180,7 @@ public boolean openNewFile() {
try {

String filename = buildFilename();
if (meta.AddToResult()) {
if (meta.isAddToResult()) {
// Add this to the result file names...
ResultFile resultFile =
new ResultFile(
Expand All @@ -202,7 +196,8 @@ public boolean openNewFile() {
if (isDetailed()) {
logDetailed("Opening output stream in nocompress mode");
}
OutputStream fos = HopVfs.getOutputStream(filename, meta.isFileAppended(), variables);
OutputStream fos =
HopVfs.getOutputStream(filename, meta.getFile().isFileAppended(), variables);
outputStream = fos;

if (isDetailed()) {
Expand Down Expand Up @@ -291,12 +286,12 @@ public boolean init() {

logBasic("Connected to database [" + meta.getConnection() + "]");

if (meta.isCreateParentFolder()) {
if (meta.getFile().isCreateParentFolder()) {
// Check for parent folder
FileObject parentfolder = null;
try {
// Get parent folder
String filename = resolve(meta.getFileName());
String filename = resolve(meta.getFile().getFileName());
parentfolder = HopVfs.getFileObject(filename, variables).getParent();
if (!parentfolder.exists()) {
logBasic(
Expand All @@ -319,15 +314,13 @@ public boolean init() {
}
}

if (!meta.isDoNotOpenNewFileInit()) {
if (!openNewFile()) {
logError("Couldn't open file [" + buildFilename() + "]");
setErrors(1L);
stopAll();
}
if (!meta.getFile().isDoNotOpenNewFileInit() && !openNewFile()) {
logError("Couldn't open file [" + buildFilename() + "]");
setErrors(1L);
stopAll();
}

tableName = resolve(meta.getTablename());
tableName = resolve(meta.getTableName());
schemaName = resolve(meta.getSchemaName());

if (Utils.isEmpty(tableName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,19 +824,19 @@ public void getData() {
if (input.getSchemaName() != null) {
wSchema.setText(input.getSchemaName());
}
if (input.getTablename() != null) {
wTable.setText(input.getTablename());
if (input.getTableName() != null) {
wTable.setText(input.getTableName());
}
if (input.getConnection() != null) {
wConnection.setText(input.getConnection());
}

if (input.getFileName() != null) {
wFilename.setText(input.getFileName());
if (input.getFile().getFileName() != null) {
wFilename.setText(input.getFile().getFileName());
}
wCreateParentFolder.setSelection(input.isCreateParentFolder());
if (input.getExtension() != null) {
wExtension.setText(input.getExtension());
wCreateParentFolder.setSelection(input.getFile().isCreateParentFolder());
if (input.getFile().getExtension() != null) {
wExtension.setText(input.getFile().getExtension());
} else {
wExtension.setText("sql");
}
Expand All @@ -845,21 +845,21 @@ public void getData() {
wFormat.setText(input.getDateFormat());
}

wSplitEvery.setText("" + input.getSplitEvery());
wAddDate.setSelection(input.isDateInFilename());
wAddTime.setSelection(input.isTimeInFilename());
wAppend.setSelection(input.isFileAppended());
wAddTransformNr.setSelection(input.isTransformNrInFilename());
wSplitEvery.setText("" + input.getFile().getSplitEvery());
wAddDate.setSelection(input.getFile().isDateInFilename());
wAddTime.setSelection(input.getFile().isTimeInFilename());
wAppend.setSelection(input.getFile().isFileAppended());
wAddTransformNr.setSelection(input.getFile().isTransformNrInFilename());

wTruncate.setSelection(input.truncateTable());
wAddCreate.setSelection(input.createTable());
wTruncate.setSelection(input.isTruncateTable());
wAddCreate.setSelection(input.isCreateTable());

if (input.getEncoding() != null) {
wEncoding.setText(input.getEncoding());
}
wAddToResult.setSelection(input.AddToResult());
wStartNewLine.setSelection(input.StartNewLine());
wDoNotOpenNewFileInit.setSelection(input.isDoNotOpenNewFileInit());
wAddToResult.setSelection(input.isAddToResult());
wStartNewLine.setSelection(input.isStartNewLine());
wDoNotOpenNewFileInit.setSelection(input.getFile().isDoNotOpenNewFileInit());

wTransformName.selectAll();
wTransformName.setFocus();
Expand All @@ -873,26 +873,26 @@ private void cancel() {

private void getInfo(SQLFileOutputMeta info) {
info.setSchemaName(wSchema.getText());
info.setTablename(wTable.getText());
info.setTableName(wTable.getText());
info.setConnection(wConnection.getText());
info.setTruncateTable(wTruncate.getSelection());
info.setCreateParentFolder(wCreateParentFolder.getSelection());
info.getFile().setCreateParentFolder(wCreateParentFolder.getSelection());

info.setCreateTable(wAddCreate.getSelection());

info.setFileName(wFilename.getText());
info.setExtension(wExtension.getText());
info.getFile().setFileName(wFilename.getText());
info.getFile().setExtension(wExtension.getText());
info.setDateFormat(wFormat.getText());
info.setSplitEvery(Const.toInt(wSplitEvery.getText(), 0));
info.setFileAppended(wAppend.getSelection());
info.setTransformNrInFilename(wAddTransformNr.getSelection());
info.setDateInFilename(wAddDate.getSelection());
info.setTimeInFilename(wAddTime.getSelection());
info.getFile().setSplitEvery(Const.toInt(wSplitEvery.getText(), 0));
info.getFile().setFileAppended(wAppend.getSelection());
info.getFile().setTransformNrInFilename(wAddTransformNr.getSelection());
info.getFile().setDateInFilename(wAddDate.getSelection());
info.getFile().setTimeInFilename(wAddTime.getSelection());

info.setEncoding(wEncoding.getText());
info.setAddToResult(wAddToResult.getSelection());
info.setStartNewLine(wStartNewLine.getSelection());
info.setDoNotOpenNewFileInit(wDoNotOpenNewFileInit.getSelection());
info.getFile().setDoNotOpenNewFileInit(wDoNotOpenNewFileInit.getSelection());
}

private void ok() {
Expand Down
Loading