-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts Resolution and Squash Merge
- Loading branch information
Chanpreet Singh
committed
Apr 7, 2022
1 parent
9c04eda
commit faa6164
Showing
19 changed files
with
412 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
src/main/java/com/dal/distributed/constant/DataConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.dal.distributed.constant; | ||
|
||
public class DataConstants { | ||
public static final String DATABASES_FOLDER_LOCATION="usr/dpg9/databases/"; | ||
public static final String DATABASES_FOLDER_LOCATION = "usr/dpg9/databases/"; | ||
|
||
public static final String LOGS_FILE_LOCATION="usr/dpg9/logs/"; | ||
public static final String LOGS_FILE_LOCATION = "usr/dpg9/logs/"; | ||
|
||
public static final String QUERY_LOGS_FILE_LOCATION = "usr/dpg9/logs/"; | ||
|
||
public static final String QUERY_LOG_FILE_NAME = "query_logs"; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/dal/distributed/constant/RelationalOperators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.dal.distributed.constant; | ||
|
||
public class RelationalOperators { | ||
public static final String EQUAL = "="; | ||
public static final String NOTEQUAL = "!="; | ||
public static final String NOTEQUAL1 = "<>"; | ||
public static final String NOTEQUAL2 = "~="; | ||
public static final String GREATER = ">"; | ||
public static final String LESS = "<"; | ||
public static final String GREATEREQUAL = ">="; | ||
public static final String LESSEQUAL = "<="; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 27 additions & 1 deletion
28
src/main/java/com/dal/distributed/queryImpl/CreateDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
package com.dal.distributed.queryImpl; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import com.dal.distributed.constant.DataConstants; | ||
import com.dal.distributed.logger.Logger; | ||
import com.dal.distributed.utils.FileOperations; | ||
|
||
public class CreateDatabase { | ||
public void execute(String query) { | ||
|
||
Logger logger = Logger.instance(); | ||
|
||
public boolean execute(String query) throws IOException { | ||
String[] sql = query.split("\\s+"); | ||
if (sql[0].equalsIgnoreCase("create") && sql[1].equalsIgnoreCase("database")) { | ||
//Remove the semicolon from database name | ||
String databaseName = sql[2].substring(0, sql[2].length() - 1).toLowerCase(); | ||
File[] databases = FileOperations.readFiles(DataConstants.DATABASES_FOLDER_LOCATION); | ||
for (File file : databases) { | ||
if (file.getName().equalsIgnoreCase(databaseName)) { | ||
logger.error("Error Code: 1007. Can't create database '" + databaseName + "'; Database exists."); | ||
return false; | ||
} | ||
} | ||
FileOperations.createNewFolder(DataConstants.DATABASES_FOLDER_LOCATION, databaseName); | ||
//FileOperations.writeToExistingFile(databaseName+"|","databases.psv", DataConstants.LOGS_FILE_LOCATION); | ||
return true; | ||
} else | ||
return false; | ||
|
||
} | ||
} |
33 changes: 32 additions & 1 deletion
33
src/main/java/com/dal/distributed/queryImpl/CreateTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
package com.dal.distributed.queryImpl; | ||
|
||
import com.dal.distributed.constant.DataConstants; | ||
import com.dal.distributed.main.Main; | ||
import com.dal.distributed.utils.FileOperations; | ||
|
||
public class CreateTable { | ||
public void execute(String query) { | ||
public boolean execute(String query) { | ||
|
||
String[] sql = query.split("\\s+"); | ||
if(sql.length>3&& sql[0].toLowerCase().equals("create")&&sql[1].toLowerCase().equals("table")) | ||
{ | ||
String mainStatement=query.substring(query.indexOf(sql[2])); | ||
String tableName=mainStatement.substring(0,mainStatement.indexOf("(")); | ||
String schema=mainStatement.substring(mainStatement.indexOf("(")+1,mainStatement.indexOf(";")-1); | ||
String columnNames=""; | ||
String[] columns= schema.split(","); | ||
int i=0; | ||
for(String col:columns) | ||
{ | ||
columnNames+=col.substring(0,col.indexOf(" ")); | ||
if(i!=columns.length-1) | ||
columnNames+="|"; | ||
i++; | ||
} | ||
schema=schema.replaceAll(",", "|"); | ||
FileOperations.writeToExistingFile(columnNames, tableName+".psv", DataConstants.DATABASES_FOLDER_LOCATION+Main.databaseName+"/"); | ||
FileOperations.writeToExistingFile(schema, tableName+"_Schema"+".psv", DataConstants.DATABASES_FOLDER_LOCATION+Main.databaseName+"/"); | ||
//FileOperations.writeToExistingFile(tableName+"|", Main.databaseName+".psv", DataConstants.LOGS_FILE_LOCATION); | ||
return true; | ||
} | ||
else | ||
return false; | ||
|
||
} | ||
|
||
} | ||
|
Oops, something went wrong.