Is there a way to retrieve the list of distribution column(s) info from the Azure Synapse JDBC drivers? I can do most of it but stuck on the WITH DISTRIBUTION WITH clause(s) part at the bottom.
For example, I just need something basic to re-create a DDL like so:
IF EXISTS(SELECT 1 FROM sys.objects WHERE [type]='U' AND [name] = 'AZURE_TEST'
AND SCHEMA_NAME(schema_id) = 'dbo')
DROP TABLE [dbo].[AZURE_TEST]
GO
CREATE TABLE [dbo].[AZURE_TEST] (
BIGINT1 BIGINT NOT NULL,
BOOLEAN1 BIT NOT NULL,
BYTEINT1 TINYINT NOT NULL PRIMARY KEY NONCLUSTERED NOT ENFORCED,
CHAR1 CHAR(1) NULL,
CHAR2 CHAR(10) NULL,
CHARACTER_VARYING1 VARCHAR(10) NULL,
CHARACTER1 CHAR(1) NOT NULL,
CHARACTER2 CHAR(10) NULL,
DATE1 DATE NULL,
DOUBLE_PRECISION1 FLOAT(15) NULL,
INTEGER1 INTEGER NULL,
INTERVAL1 VARCHAR(50) NULL,
NATIONAL_CHARACTER_VARYING2 NVARCHAR(10) NULL,
NUMERIC1 NUMERIC(18, 0) NULL,
NUMERIC2 NUMERIC(10, 0) NOT NULL,
NUMERIC3 NUMERIC(10, 2) NULL,
REAL1 REAL NULL,
SMALLINT1 SMALLINT NULL,
TIME1 TIME NULL,
TIMESTAMP1 DATETIME2 NULL
)
WITH
(
DISTRIBUTION = HASH ( [BIGINT1] ),
CLUSTERED COLUMNSTORE INDEX
)
GO
You can retrieve the columns used for the DISTRIBUTION for a given table by running the next sql:
SELECT c.name FROM sys.columns AS c
INNER JOIN sys.tables AS t ON t.object_id = c.object_id
INNER JOIN sys.schemas AS s ON s.schema_id = t.schema_id
INNER JOIN sys.pdw_column_distribution_properties AS d ON t.object_id = d.object_id AND d.column_id = c.column_id
WHERE t.name = 'table_name' AND s.name = 'schema_name' AND d.distribution_ordinal <> 0;
I have the following query in my code:
DynamicQuery journalArticleDynamicQuery = JournalArticleLocalServiceUtil.dynamicQuery();
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName("DDMStructureKey").eq("MY_STRUCTURE"));
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(groupId));
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.FOLDER_ID).eq(folderId));
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.STATUS).eq(0));
journalArticleDynamicQuery.addOrder(OrderFactoryUtil.desc(Field.DISPLAY_DATE));
JournalArticleLocalServiceUtil.dynamicQuery(journalArticleDynamicQuery, 0, 30)
But this is returning all versions of the JournalArticle. My question is: how can I query only the latest version of the JournalArticle using the previous query?
I have posted this in the Liferay Foruns but I didn't get any response yet.
I have found out that if you use the "search" method and pass the "version" parameter as null, you get only the latest versions of the JournalArticle:
List<JournalArticle> journalArticles = JournalArticleLocalServiceUtil.search(
themeDisplay.getCompanyId(),
themeDisplay.getScopeGroupId(),
folderIds,
JournalArticleConstants.CLASSNAME_ID_DEFAULT,
null,
null,
null,
null,
null,
"MY_STRUCTURE",
null,
myDate,
null,
0,
null,
true,
startIndex,
endIndex,
OrderByComparatorFactoryUtil.create("JournalArticle", Field.DISPLAY_DATE, false)
);
I am trying to implement post request using spring data jpa. I am trying to add new room in room table with some values. Some of the column from room table are not null I set that with default. But when I am inserting I am getting error as violates not-null constraint.
RoomService class
// Add new Room Details
public String addNewRoom(#RequestBody RoomInformation roomInfo) {
Room roomRecord = new Room();
if(roomInfo.nCampusId != 0)
roomRecord.nCampusId = roomInfo.nCampusId;
if(roomInfo.nBuildId != 0)
roomRecord.nBuildId=roomInfo.nBuildId;
if(roomInfo.nCRTCodeId !=0)
roomRecord.nCRTCodeId=roomInfo.nCRTCodeId;
roomRecord.nInstId=roomInfo.nInstId;
roomRecord.sRoomNumber=roomInfo.sRoomNumber;
roomRecord.sRoomDesc=roomInfo.sRoomDesc;
roomRecord.nArea=roomInfo.nArea;
roomRecord.sFloor=roomInfo.sFloor;
roomRecord.bIsActive= true;
roomRepository.save(roomRecord);
return "New room added sucessfully";
}
Room Table
CREATE TABLE public.room
(
nroom_id numeric(18,0) NOT NULL DEFAULT nextval('room_seq'::regclass),
ncampus_id numeric(18,0),
nbuild_id numeric(18,0),
ninst_id numeric(18,0) NOT NULL DEFAULT 0,
sfloor character varying(10) COLLATE pg_catalog."default",
sroom_number character varying(10) COLLATE pg_catalog."default",
sroom_desc character varying(255) COLLATE pg_catalog."default",
scomments text COLLATE pg_catalog."default",
daccepted_date timestamp(3) without time zone,
ssurveyor character varying(255) COLLATE pg_catalog."default",
narea integer,
ncrt_code_id numeric(18,0),
ncmn_room_bln smallint,
nunvalidated_bln smallint,
sbfr_field character varying(50) COLLATE pg_catalog."default",
ntemp_room_id numeric(18,0),
bis_active boolean NOT NULL DEFAULT false,
bis_jointuse boolean NOT NULL DEFAULT false,
sstations_desc character varying(25) COLLATE pg_catalog."default",
ddeleted_on timestamp(3) without time zone,
ndeleted_by numeric(18,0),
bis_incluster boolean NOT NULL DEFAULT false,
bis_service_center_activity boolean NOT NULL DEFAULT false,
service_center_comments text COLLATE pg_catalog."default",
CONSTRAINT pk_roomdeails PRIMARY KEY (nroom_id),
)
Error at console
Null value in column "bis_jointuse" violates not-null constraint
Detail: Failing row contains (1203521, 270, 11135, 106, 0, 10, abc, null, null, null, 22, 2122, null, null, null, null, t, null, null, null, null, null, null, null).
You need to skip column or provide DEFAULT keyword instead of explicit NULL:
INSERT INTO tab(col1,...,bis_jointuse)
VALUES (22, ..., DEFAULT);
-- skipping column
INSERT INTO tab(col1,...)
VALUES (22,...);
Those values are not null in table that I set with default value. But default value is not taking when I am trying to insert.
As far I as know only Oracle supports such construct: DEFAULT Values On Explicit NULLs
In the previous section we saw default values are only used when a column is not referenced in an insert statement. If the column is referenced, even when supplying the value NULL, the default value is not used. Oracle 12c allows you to modify this behaviour using the ON NULL clause in the default definition.
CREATE TABLE t2 (
col1 NUMBER DEFAULT 1,
col2 NUMBER DEFAULT ON NULL 2,
description VARCHAR2(30)
);
Currently, i am trying to add rows to a JTable in java swing and getting the following output. Null getting appended with the first cell showing java.lang.someerror
This is the output with cells showing error
, I cant able to append strings in the table. Getting an error like
cannot convert string to object
Need to insert to the table (String Object[][]) which is in the code follows as
class SimpleTableExample
extends JFrame
{
// Instance attributes used in this example
private JPanel topPanel;
private JTable table;
private JScrollPane scrollPane;
// Constructor of main frame
public SimpleTableExample()
{
// Set the frame characteristics
setTitle( "Simple Table Application" );
setSize( 1100, 150 );
setBackground( Color.gray );
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create columns names
String columnNames[] = { " Date & Time", "VRP", "VYP", "VBP", "CRP","CYP","CBP","PO","BM","ARM","WT","RH","CNT","BCC","W","F","L","status"};
// Create some data
String dataValues[][] =
{
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
{ null, null, null , null, null, null, null, null , null, null,null, null, null , null, null, null, null, null },
};
String Object[][] = {{"85", "85","85","85","85","85","85","85","85","85","85","85","85","85","85","85","85","85"}};
DefaultTableModel dm = new DefaultTableModel(0,0);
dm.setColumnIdentifiers(columnNames);
// Create a new table instance
table = new JTable(dm);
TableColumn column = null;
for(int i =0; i<18; i++){
column = table.getColumnModel().getColumn(i);
if(i==0)
{
column.setPreferredWidth(100);
}
else{
column.setPreferredWidth(40);
}
}
table.setModel(dm);
/* i have tried to use vector for insertion didn't work
Vector <Object> data = new Vector <Object>();
data.add(null);
data.add(null);
dm.addRow(data); */
((DefaultTableModel) ((JTable) table).getModel()).addRow(new Object[]{}); //for this code row got inserted with some error displaying in first cell
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
topPanel.add( scrollPane, BorderLayout.CENTER );
}
// Main entry point for this example
public static void main( String args[] )
{
// Create an instance of the test application
SimpleTableExample mainFrame = new SimpleTableExample();
mainFrame.setVisible( true );
}
}
((DefaultTableModel) ((JTable) table).getModel()).addRow(new Object[]{"85","85","85","85","85","85","85","85","85","85","85","85","85","85","85","85","85","85"});
If I use this, getting this error...
Type mismatch: cannot convert from String to
Object
Kindly anyone help with this issue
The constructor is asking you for an Object array, which is declared with additional braces. I suspect that you are using a String[] instead of a Object[][]:
Object[][] defaultValues={
{"content1"},
{"content2"}
};
It has worked for me when using the constructor new DefaultTableModel(Object[][] data,Object[] columnames);.
I am using eclipse and following http://www.eclipse.org/articles/article.php?file=Article-EclipseDbWebapps/index.html and it all works fine except when I try to run my own sql code.
Here it is:
CREATE TABLE honscores (
idhonscores INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
Name varchar(25) NOT NULL,
Characters VARCHAR(25) NOT NULL,
Kills integer(11) NOT NULL,
Deaths integer(11) NOT NULL,
Assists integer(11) NOT NULL,
XPM integer(11) NOT NULL,
CK integer(11) NOT NULL);
Any help will be appreciated.
Here is the error message :
Syntax error: Encountered "(" at line 5, column 20.
Elapsed Time: 0 hr, 0 min, 0 sec, 0 ms.
CREATE TABLE app.honscores ( //schema name is before the table name
idhonscores INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
Name varchar(25) NOT NULL,
Characters VARCHAR(25) NOT NULL,
Kills integer NOT NULL,
Deaths integer NOT NULL,
Assists integer NOT NULL,
XPM integer NOT NULL,
CK integer NOT NULL
);
Im pretty sure this is how I fixed it